Compare commits

..

No commits in common. "373b620a0b47e117e4043012359e508897785ab2" and "9fa61e4caf93f7088dc618be887462a6c6da47cb" have entirely different histories.

20 changed files with 1156 additions and 695 deletions

766
package-lock.json generated
View File

@ -1,20 +1,56 @@
{ {
"name": "f0ckv2", "name": "f0ckv2",
"version": "2.2.0", "version": "2.1.0",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "f0ckv2", "name": "f0ckv2",
"version": "2.2.0", "version": "2.1.0",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"cuffeo": "^1.0.7-3", "cuffeo": "^1.0.7-3",
"flumm-fetch": "^1.0.1", "flumm-fetch-cookies": "^1.4.0",
"flummpress": "^2.0.4", "flummpress": "^2.0.4",
"postgres": "^3.0.1" "knex": "^0.95.15",
"pg": "^8.7.1",
"pg-native": "^3.0.0"
} }
}, },
"node_modules/bindings": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz",
"integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==",
"dependencies": {
"file-uri-to-path": "1.0.0"
}
},
"node_modules/buffer-writer": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/buffer-writer/-/buffer-writer-2.0.0.tgz",
"integrity": "sha512-a7ZpuTZU1TRtnwyCNW3I5dc0wWNC3VR9S++Ewyk2HHZdrO3CQJqSpd+95Us590V6AL7JqUAH2IwZ/398PmNFgw==",
"engines": {
"node": ">=4"
}
},
"node_modules/colorette": {
"version": "2.0.16",
"resolved": "https://registry.npmjs.org/colorette/-/colorette-2.0.16.tgz",
"integrity": "sha512-hUewv7oMjCp+wkBv5Rm0v87eJhq4woh5rSR+42YSQJKecCqgIqNkZ6lAlQms/BwHPJA5NKMRlpxPRv0n8HQW6g=="
},
"node_modules/commander": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-7.2.0.tgz",
"integrity": "sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw==",
"engines": {
"node": ">= 10"
}
},
"node_modules/core-util-is": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ=="
},
"node_modules/cuffeo": { "node_modules/cuffeo": {
"version": "1.0.7-3", "version": "1.0.7-3",
"resolved": "https://registry.npmjs.org/cuffeo/-/cuffeo-1.0.7-3.tgz", "resolved": "https://registry.npmjs.org/cuffeo/-/cuffeo-1.0.7-3.tgz",
@ -23,6 +59,43 @@
"flumm-fetch-cookies": "^1.4.0" "flumm-fetch-cookies": "^1.4.0"
} }
}, },
"node_modules/debug": {
"version": "4.3.2",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz",
"integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==",
"dependencies": {
"ms": "2.1.2"
},
"engines": {
"node": ">=6.0"
},
"peerDependenciesMeta": {
"supports-color": {
"optional": true
}
}
},
"node_modules/escalade": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz",
"integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==",
"engines": {
"node": ">=6"
}
},
"node_modules/esm": {
"version": "3.2.25",
"resolved": "https://registry.npmjs.org/esm/-/esm-3.2.25.tgz",
"integrity": "sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==",
"engines": {
"node": ">=6"
}
},
"node_modules/file-uri-to-path": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",
"integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw=="
},
"node_modules/flumm-fetch": { "node_modules/flumm-fetch": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/flumm-fetch/-/flumm-fetch-1.0.1.tgz", "resolved": "https://registry.npmjs.org/flumm-fetch/-/flumm-fetch-1.0.1.tgz",
@ -44,17 +117,400 @@
"resolved": "https://registry.npmjs.org/flummpress/-/flummpress-2.0.4.tgz", "resolved": "https://registry.npmjs.org/flummpress/-/flummpress-2.0.4.tgz",
"integrity": "sha512-AuEf/VnfC9hWqw+/0aH+Y+c8UgZ6CX/wVN8RR8V9btvYhIzLTJzVlyC0oTg5yrqLMUGaL9y8YRBjg2hKbFm94A==" "integrity": "sha512-AuEf/VnfC9hWqw+/0aH+Y+c8UgZ6CX/wVN8RR8V9btvYhIzLTJzVlyC0oTg5yrqLMUGaL9y8YRBjg2hKbFm94A=="
}, },
"node_modules/postgres": { "node_modules/function-bind": {
"version": "3.0.2", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/postgres/-/postgres-3.0.2.tgz", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
"integrity": "sha512-sHkEGAnPVqRclh5oIr9S9e/VNX0/MUb2PgS9bl/0wnI8WrHhzMmxqq/fAkMZKUUrC3Lfa4qaNh1dyDPH4Q8V0w==", "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A=="
},
"node_modules/getopts": {
"version": "2.2.5",
"resolved": "https://registry.npmjs.org/getopts/-/getopts-2.2.5.tgz",
"integrity": "sha512-9jb7AW5p3in+IiJWhQiZmmwkpLaR/ccTWdWQCtZM66HJcHHLegowh4q4tSD7gouUyeNvFWRavfK9GXosQHDpFA=="
},
"node_modules/has": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz",
"integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==",
"dependencies": {
"function-bind": "^1.1.1"
},
"engines": {
"node": ">= 0.4.0"
}
},
"node_modules/inherits": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
},
"node_modules/interpret": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/interpret/-/interpret-2.2.0.tgz",
"integrity": "sha512-Ju0Bz/cEia55xDwUWEa8+olFpCiQoypjnQySseKtmjNrnps3P+xfpUmGr90T7yjlVJmOtybRvPXhKMbHr+fWnw==",
"engines": {
"node": ">= 0.10"
}
},
"node_modules/is-core-module": {
"version": "2.8.1",
"resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.8.1.tgz",
"integrity": "sha512-SdNCUs284hr40hFTFP6l0IfZ/RSrMXF3qgoRHd3/79unUTvrFO/JoXwkGm+5J/Oe3E/b5GsnG330uUNgRpu1PA==",
"dependencies": {
"has": "^1.0.3"
},
"funding": { "funding": {
"type": "individual", "url": "https://github.com/sponsors/ljharb"
"url": "https://github.com/sponsors/porsager" }
},
"node_modules/isarray": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
"integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8="
},
"node_modules/knex": {
"version": "0.95.15",
"resolved": "https://registry.npmjs.org/knex/-/knex-0.95.15.tgz",
"integrity": "sha512-Loq6WgHaWlmL2bfZGWPsy4l8xw4pOE+tmLGkPG0auBppxpI0UcK+GYCycJcqz9W54f2LiGewkCVLBm3Wq4ur/w==",
"dependencies": {
"colorette": "2.0.16",
"commander": "^7.1.0",
"debug": "4.3.2",
"escalade": "^3.1.1",
"esm": "^3.2.25",
"getopts": "2.2.5",
"interpret": "^2.2.0",
"lodash": "^4.17.21",
"pg-connection-string": "2.5.0",
"rechoir": "0.7.0",
"resolve-from": "^5.0.0",
"tarn": "^3.0.1",
"tildify": "2.0.0"
},
"bin": {
"knex": "bin/cli.js"
},
"engines": {
"node": ">=10"
},
"peerDependenciesMeta": {
"mysql": {
"optional": true
},
"mysql2": {
"optional": true
},
"pg": {
"optional": true
},
"pg-native": {
"optional": true
},
"sqlite3": {
"optional": true
},
"tedious": {
"optional": true
}
}
},
"node_modules/libpq": {
"version": "1.8.9",
"resolved": "https://registry.npmjs.org/libpq/-/libpq-1.8.9.tgz",
"integrity": "sha512-herU0STiW3+/XBoYRycKKf49O9hBKK0JbdC2QmvdC5pyCSu8prb9idpn5bUSbxj8XwcEsWPWWWwTDZE9ZTwJ7g==",
"hasInstallScript": true,
"dependencies": {
"bindings": "1.5.0",
"nan": "^2.14.0"
}
},
"node_modules/lodash": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
},
"node_modules/ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
},
"node_modules/nan": {
"version": "2.15.0",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.15.0.tgz",
"integrity": "sha512-8ZtvEnA2c5aYCZYd1cvgdnU6cqwixRoYg70xPLWUws5ORTa/lnw+u4amixRS/Ac5U5mQVgp9pnlSUnbNWFaWZQ=="
},
"node_modules/packet-reader": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/packet-reader/-/packet-reader-1.0.0.tgz",
"integrity": "sha512-HAKu/fG3HpHFO0AA8WE8q2g+gBJaZ9MG7fcKk+IJPLTGAD6Psw4443l+9DGRbOIh3/aXr7Phy0TjilYivJo5XQ=="
},
"node_modules/path-parse": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz",
"integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw=="
},
"node_modules/pg": {
"version": "8.7.3",
"resolved": "https://registry.npmjs.org/pg/-/pg-8.7.3.tgz",
"integrity": "sha512-HPmH4GH4H3AOprDJOazoIcpI49XFsHCe8xlrjHkWiapdbHK+HLtbm/GQzXYAZwmPju/kzKhjaSfMACG+8cgJcw==",
"dependencies": {
"buffer-writer": "2.0.0",
"packet-reader": "1.0.0",
"pg-connection-string": "^2.5.0",
"pg-pool": "^3.5.1",
"pg-protocol": "^1.5.0",
"pg-types": "^2.1.0",
"pgpass": "1.x"
},
"engines": {
"node": ">= 8.0.0"
},
"peerDependencies": {
"pg-native": ">=2.0.0"
},
"peerDependenciesMeta": {
"pg-native": {
"optional": true
}
}
},
"node_modules/pg-connection-string": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.5.0.tgz",
"integrity": "sha512-r5o/V/ORTA6TmUnyWZR9nCj1klXCO2CEKNRlVuJptZe85QuhFayC7WeMic7ndayT5IRIR0S0xFxFi2ousartlQ=="
},
"node_modules/pg-int8": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz",
"integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==",
"engines": {
"node": ">=4.0.0"
}
},
"node_modules/pg-native": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/pg-native/-/pg-native-3.0.0.tgz",
"integrity": "sha512-qZZyywXJ8O4lbiIN7mn6vXIow1fd3QZFqzRe+uET/SZIXvCa3HBooXQA4ZU8EQX8Ae6SmaYtDGLp5DwU+8vrfg==",
"dependencies": {
"libpq": "^1.7.0",
"pg-types": "^1.12.1",
"readable-stream": "1.0.31"
}
},
"node_modules/pg-native/node_modules/pg-types": {
"version": "1.13.0",
"resolved": "https://registry.npmjs.org/pg-types/-/pg-types-1.13.0.tgz",
"integrity": "sha512-lfKli0Gkl/+za/+b6lzENajczwZHc7D5kiUCZfgm914jipD2kIOIvEkAhZ8GrW3/TUoP9w8FHjwpPObBye5KQQ==",
"dependencies": {
"pg-int8": "1.0.1",
"postgres-array": "~1.0.0",
"postgres-bytea": "~1.0.0",
"postgres-date": "~1.0.0",
"postgres-interval": "^1.1.0"
}
},
"node_modules/pg-native/node_modules/postgres-array": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-1.0.3.tgz",
"integrity": "sha512-5wClXrAP0+78mcsNX3/ithQ5exKvCyK5lr5NEEEeGwwM6NJdQgzIJBVxLvRW+huFpX92F2QnZ5CcokH0VhK2qQ==",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/pg-pool": {
"version": "3.5.1",
"resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.5.1.tgz",
"integrity": "sha512-6iCR0wVrro6OOHFsyavV+i6KYL4lVNyYAB9RD18w66xSzN+d8b66HiwuP30Gp1SH5O9T82fckkzsRjlrhD0ioQ==",
"peerDependencies": {
"pg": ">=8.0"
}
},
"node_modules/pg-protocol": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.5.0.tgz",
"integrity": "sha512-muRttij7H8TqRNu/DxrAJQITO4Ac7RmX3Klyr/9mJEOBeIpgnF8f9jAfRz5d3XwQZl5qBjF9gLsUtMPJE0vezQ=="
},
"node_modules/pg-types": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz",
"integrity": "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==",
"dependencies": {
"pg-int8": "1.0.1",
"postgres-array": "~2.0.0",
"postgres-bytea": "~1.0.0",
"postgres-date": "~1.0.4",
"postgres-interval": "^1.1.0"
},
"engines": {
"node": ">=4"
}
},
"node_modules/pgpass": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/pgpass/-/pgpass-1.0.5.tgz",
"integrity": "sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==",
"dependencies": {
"split2": "^4.1.0"
}
},
"node_modules/postgres-array": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz",
"integrity": "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==",
"engines": {
"node": ">=4"
}
},
"node_modules/postgres-bytea": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.0.tgz",
"integrity": "sha1-AntTPAqokOJtFy1Hz5zOzFIazTU=",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/postgres-date": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.7.tgz",
"integrity": "sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/postgres-interval": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz",
"integrity": "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==",
"dependencies": {
"xtend": "^4.0.0"
},
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/readable-stream": {
"version": "1.0.31",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.31.tgz",
"integrity": "sha1-jyUC4LyeOw2huUUgqrtOJgPsr64=",
"dependencies": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.1",
"isarray": "0.0.1",
"string_decoder": "~0.10.x"
}
},
"node_modules/rechoir": {
"version": "0.7.0",
"resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.7.0.tgz",
"integrity": "sha512-ADsDEH2bvbjltXEP+hTIAmeFekTFK0V2BTxMkok6qILyAJEXV0AFfoWcAq4yfll5VdIMd/RVXq0lR+wQi5ZU3Q==",
"dependencies": {
"resolve": "^1.9.0"
},
"engines": {
"node": ">= 0.10"
}
},
"node_modules/resolve": {
"version": "1.22.0",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.0.tgz",
"integrity": "sha512-Hhtrw0nLeSrFQ7phPp4OOcVjLPIeMnRlr5mcnVuMe7M/7eBn98A3hmFRLoFo3DLZkivSYwhRUJTyPyWAk56WLw==",
"dependencies": {
"is-core-module": "^2.8.1",
"path-parse": "^1.0.7",
"supports-preserve-symlinks-flag": "^1.0.0"
},
"bin": {
"resolve": "bin/resolve"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/resolve-from": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-5.0.0.tgz",
"integrity": "sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==",
"engines": {
"node": ">=8"
}
},
"node_modules/split2": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/split2/-/split2-4.1.0.tgz",
"integrity": "sha512-VBiJxFkxiXRlUIeyMQi8s4hgvKCSjtknJv/LVYbrgALPwf5zSKmEwV9Lst25AkvMDnvxODugjdl6KZgwKM1WYQ==",
"engines": {
"node": ">= 10.x"
}
},
"node_modules/string_decoder": {
"version": "0.10.31",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ="
},
"node_modules/supports-preserve-symlinks-flag": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz",
"integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==",
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/tarn": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/tarn/-/tarn-3.0.2.tgz",
"integrity": "sha512-51LAVKUSZSVfI05vjPESNc5vwqqZpbXCsU+/+wxlOrUjk2SnFTt97v9ZgQrD4YmxYW1Px6w2KjaDitCfkvgxMQ==",
"engines": {
"node": ">=8.0.0"
}
},
"node_modules/tildify": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/tildify/-/tildify-2.0.0.tgz",
"integrity": "sha512-Cc+OraorugtXNfs50hU9KS369rFXCfgGLpfCfvlc+Ud5u6VWmUQsOAa9HbTvheQdYnrdJqqv1e5oIqXppMYnSw==",
"engines": {
"node": ">=8"
}
},
"node_modules/xtend": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
"integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==",
"engines": {
"node": ">=0.4"
} }
} }
}, },
"dependencies": { "dependencies": {
"bindings": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz",
"integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==",
"requires": {
"file-uri-to-path": "1.0.0"
}
},
"buffer-writer": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/buffer-writer/-/buffer-writer-2.0.0.tgz",
"integrity": "sha512-a7ZpuTZU1TRtnwyCNW3I5dc0wWNC3VR9S++Ewyk2HHZdrO3CQJqSpd+95Us590V6AL7JqUAH2IwZ/398PmNFgw=="
},
"colorette": {
"version": "2.0.16",
"resolved": "https://registry.npmjs.org/colorette/-/colorette-2.0.16.tgz",
"integrity": "sha512-hUewv7oMjCp+wkBv5Rm0v87eJhq4woh5rSR+42YSQJKecCqgIqNkZ6lAlQms/BwHPJA5NKMRlpxPRv0n8HQW6g=="
},
"commander": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-7.2.0.tgz",
"integrity": "sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw=="
},
"core-util-is": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ=="
},
"cuffeo": { "cuffeo": {
"version": "1.0.7-3", "version": "1.0.7-3",
"resolved": "https://registry.npmjs.org/cuffeo/-/cuffeo-1.0.7-3.tgz", "resolved": "https://registry.npmjs.org/cuffeo/-/cuffeo-1.0.7-3.tgz",
@ -63,6 +519,29 @@
"flumm-fetch-cookies": "^1.4.0" "flumm-fetch-cookies": "^1.4.0"
} }
}, },
"debug": {
"version": "4.3.2",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz",
"integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==",
"requires": {
"ms": "2.1.2"
}
},
"escalade": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz",
"integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw=="
},
"esm": {
"version": "3.2.25",
"resolved": "https://registry.npmjs.org/esm/-/esm-3.2.25.tgz",
"integrity": "sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA=="
},
"file-uri-to-path": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",
"integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw=="
},
"flumm-fetch": { "flumm-fetch": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/flumm-fetch/-/flumm-fetch-1.0.1.tgz", "resolved": "https://registry.npmjs.org/flumm-fetch/-/flumm-fetch-1.0.1.tgz",
@ -81,10 +560,271 @@
"resolved": "https://registry.npmjs.org/flummpress/-/flummpress-2.0.4.tgz", "resolved": "https://registry.npmjs.org/flummpress/-/flummpress-2.0.4.tgz",
"integrity": "sha512-AuEf/VnfC9hWqw+/0aH+Y+c8UgZ6CX/wVN8RR8V9btvYhIzLTJzVlyC0oTg5yrqLMUGaL9y8YRBjg2hKbFm94A==" "integrity": "sha512-AuEf/VnfC9hWqw+/0aH+Y+c8UgZ6CX/wVN8RR8V9btvYhIzLTJzVlyC0oTg5yrqLMUGaL9y8YRBjg2hKbFm94A=="
}, },
"postgres": { "function-bind": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A=="
},
"getopts": {
"version": "2.2.5",
"resolved": "https://registry.npmjs.org/getopts/-/getopts-2.2.5.tgz",
"integrity": "sha512-9jb7AW5p3in+IiJWhQiZmmwkpLaR/ccTWdWQCtZM66HJcHHLegowh4q4tSD7gouUyeNvFWRavfK9GXosQHDpFA=="
},
"has": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz",
"integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==",
"requires": {
"function-bind": "^1.1.1"
}
},
"inherits": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
},
"interpret": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/interpret/-/interpret-2.2.0.tgz",
"integrity": "sha512-Ju0Bz/cEia55xDwUWEa8+olFpCiQoypjnQySseKtmjNrnps3P+xfpUmGr90T7yjlVJmOtybRvPXhKMbHr+fWnw=="
},
"is-core-module": {
"version": "2.8.1",
"resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.8.1.tgz",
"integrity": "sha512-SdNCUs284hr40hFTFP6l0IfZ/RSrMXF3qgoRHd3/79unUTvrFO/JoXwkGm+5J/Oe3E/b5GsnG330uUNgRpu1PA==",
"requires": {
"has": "^1.0.3"
}
},
"isarray": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
"integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8="
},
"knex": {
"version": "0.95.15",
"resolved": "https://registry.npmjs.org/knex/-/knex-0.95.15.tgz",
"integrity": "sha512-Loq6WgHaWlmL2bfZGWPsy4l8xw4pOE+tmLGkPG0auBppxpI0UcK+GYCycJcqz9W54f2LiGewkCVLBm3Wq4ur/w==",
"requires": {
"colorette": "2.0.16",
"commander": "^7.1.0",
"debug": "4.3.2",
"escalade": "^3.1.1",
"esm": "^3.2.25",
"getopts": "2.2.5",
"interpret": "^2.2.0",
"lodash": "^4.17.21",
"pg-connection-string": "2.5.0",
"rechoir": "0.7.0",
"resolve-from": "^5.0.0",
"tarn": "^3.0.1",
"tildify": "2.0.0"
}
},
"libpq": {
"version": "1.8.9",
"resolved": "https://registry.npmjs.org/libpq/-/libpq-1.8.9.tgz",
"integrity": "sha512-herU0STiW3+/XBoYRycKKf49O9hBKK0JbdC2QmvdC5pyCSu8prb9idpn5bUSbxj8XwcEsWPWWWwTDZE9ZTwJ7g==",
"requires": {
"bindings": "1.5.0",
"nan": "^2.14.0"
}
},
"lodash": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
},
"ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
},
"nan": {
"version": "2.15.0",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.15.0.tgz",
"integrity": "sha512-8ZtvEnA2c5aYCZYd1cvgdnU6cqwixRoYg70xPLWUws5ORTa/lnw+u4amixRS/Ac5U5mQVgp9pnlSUnbNWFaWZQ=="
},
"packet-reader": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/packet-reader/-/packet-reader-1.0.0.tgz",
"integrity": "sha512-HAKu/fG3HpHFO0AA8WE8q2g+gBJaZ9MG7fcKk+IJPLTGAD6Psw4443l+9DGRbOIh3/aXr7Phy0TjilYivJo5XQ=="
},
"path-parse": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz",
"integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw=="
},
"pg": {
"version": "8.7.3",
"resolved": "https://registry.npmjs.org/pg/-/pg-8.7.3.tgz",
"integrity": "sha512-HPmH4GH4H3AOprDJOazoIcpI49XFsHCe8xlrjHkWiapdbHK+HLtbm/GQzXYAZwmPju/kzKhjaSfMACG+8cgJcw==",
"requires": {
"buffer-writer": "2.0.0",
"packet-reader": "1.0.0",
"pg-connection-string": "^2.5.0",
"pg-pool": "^3.5.1",
"pg-protocol": "^1.5.0",
"pg-types": "^2.1.0",
"pgpass": "1.x"
}
},
"pg-connection-string": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.5.0.tgz",
"integrity": "sha512-r5o/V/ORTA6TmUnyWZR9nCj1klXCO2CEKNRlVuJptZe85QuhFayC7WeMic7ndayT5IRIR0S0xFxFi2ousartlQ=="
},
"pg-int8": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz",
"integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw=="
},
"pg-native": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/pg-native/-/pg-native-3.0.0.tgz",
"integrity": "sha512-qZZyywXJ8O4lbiIN7mn6vXIow1fd3QZFqzRe+uET/SZIXvCa3HBooXQA4ZU8EQX8Ae6SmaYtDGLp5DwU+8vrfg==",
"requires": {
"libpq": "^1.7.0",
"pg-types": "^1.12.1",
"readable-stream": "1.0.31"
},
"dependencies": {
"pg-types": {
"version": "1.13.0",
"resolved": "https://registry.npmjs.org/pg-types/-/pg-types-1.13.0.tgz",
"integrity": "sha512-lfKli0Gkl/+za/+b6lzENajczwZHc7D5kiUCZfgm914jipD2kIOIvEkAhZ8GrW3/TUoP9w8FHjwpPObBye5KQQ==",
"requires": {
"pg-int8": "1.0.1",
"postgres-array": "~1.0.0",
"postgres-bytea": "~1.0.0",
"postgres-date": "~1.0.0",
"postgres-interval": "^1.1.0"
}
},
"postgres-array": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-1.0.3.tgz",
"integrity": "sha512-5wClXrAP0+78mcsNX3/ithQ5exKvCyK5lr5NEEEeGwwM6NJdQgzIJBVxLvRW+huFpX92F2QnZ5CcokH0VhK2qQ=="
}
}
},
"pg-pool": {
"version": "3.5.1",
"resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.5.1.tgz",
"integrity": "sha512-6iCR0wVrro6OOHFsyavV+i6KYL4lVNyYAB9RD18w66xSzN+d8b66HiwuP30Gp1SH5O9T82fckkzsRjlrhD0ioQ==",
"requires": {}
},
"pg-protocol": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.5.0.tgz",
"integrity": "sha512-muRttij7H8TqRNu/DxrAJQITO4Ac7RmX3Klyr/9mJEOBeIpgnF8f9jAfRz5d3XwQZl5qBjF9gLsUtMPJE0vezQ=="
},
"pg-types": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz",
"integrity": "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==",
"requires": {
"pg-int8": "1.0.1",
"postgres-array": "~2.0.0",
"postgres-bytea": "~1.0.0",
"postgres-date": "~1.0.4",
"postgres-interval": "^1.1.0"
}
},
"pgpass": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/pgpass/-/pgpass-1.0.5.tgz",
"integrity": "sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==",
"requires": {
"split2": "^4.1.0"
}
},
"postgres-array": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz",
"integrity": "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA=="
},
"postgres-bytea": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.0.tgz",
"integrity": "sha1-AntTPAqokOJtFy1Hz5zOzFIazTU="
},
"postgres-date": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.7.tgz",
"integrity": "sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q=="
},
"postgres-interval": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz",
"integrity": "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==",
"requires": {
"xtend": "^4.0.0"
}
},
"readable-stream": {
"version": "1.0.31",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.31.tgz",
"integrity": "sha1-jyUC4LyeOw2huUUgqrtOJgPsr64=",
"requires": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.1",
"isarray": "0.0.1",
"string_decoder": "~0.10.x"
}
},
"rechoir": {
"version": "0.7.0",
"resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.7.0.tgz",
"integrity": "sha512-ADsDEH2bvbjltXEP+hTIAmeFekTFK0V2BTxMkok6qILyAJEXV0AFfoWcAq4yfll5VdIMd/RVXq0lR+wQi5ZU3Q==",
"requires": {
"resolve": "^1.9.0"
}
},
"resolve": {
"version": "1.22.0",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.0.tgz",
"integrity": "sha512-Hhtrw0nLeSrFQ7phPp4OOcVjLPIeMnRlr5mcnVuMe7M/7eBn98A3hmFRLoFo3DLZkivSYwhRUJTyPyWAk56WLw==",
"requires": {
"is-core-module": "^2.8.1",
"path-parse": "^1.0.7",
"supports-preserve-symlinks-flag": "^1.0.0"
}
},
"resolve-from": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-5.0.0.tgz",
"integrity": "sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw=="
},
"split2": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/split2/-/split2-4.1.0.tgz",
"integrity": "sha512-VBiJxFkxiXRlUIeyMQi8s4hgvKCSjtknJv/LVYbrgALPwf5zSKmEwV9Lst25AkvMDnvxODugjdl6KZgwKM1WYQ=="
},
"string_decoder": {
"version": "0.10.31",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ="
},
"supports-preserve-symlinks-flag": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz",
"integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w=="
},
"tarn": {
"version": "3.0.2", "version": "3.0.2",
"resolved": "https://registry.npmjs.org/postgres/-/postgres-3.0.2.tgz", "resolved": "https://registry.npmjs.org/tarn/-/tarn-3.0.2.tgz",
"integrity": "sha512-sHkEGAnPVqRclh5oIr9S9e/VNX0/MUb2PgS9bl/0wnI8WrHhzMmxqq/fAkMZKUUrC3Lfa4qaNh1dyDPH4Q8V0w==" "integrity": "sha512-51LAVKUSZSVfI05vjPESNc5vwqqZpbXCsU+/+wxlOrUjk2SnFTt97v9ZgQrD4YmxYW1Px6w2KjaDitCfkvgxMQ=="
},
"tildify": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/tildify/-/tildify-2.0.0.tgz",
"integrity": "sha512-Cc+OraorugtXNfs50hU9KS369rFXCfgGLpfCfvlc+Ud5u6VWmUQsOAa9HbTvheQdYnrdJqqv1e5oIqXppMYnSw=="
},
"xtend": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
"integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ=="
} }
} }
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "f0ckv2", "name": "f0ckv2",
"version": "2.2.0", "version": "2.1.0",
"description": "f0ck, kennste?", "description": "f0ck, kennste?",
"main": "index.mjs", "main": "index.mjs",
"scripts": { "scripts": {
@ -15,8 +15,10 @@
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"cuffeo": "^1.0.7-3", "cuffeo": "^1.0.7-3",
"flumm-fetch": "^1.0.1", "flumm-fetch-cookies": "^1.4.0",
"flummpress": "^2.0.4", "flummpress": "^2.0.4",
"postgres": "^3.0.1" "knex": "^0.95.15",
"pg": "^8.7.1",
"pg-native": "^3.0.0"
} }
} }

View File

@ -1,6 +1,6 @@
import crypto from "crypto"; import crypto from "crypto";
import util from "util"; import util from "util";
import db from "./sql.mjs"; import sql from "./sql.mjs";
const scrypt = util.promisify(crypto.scrypt); const scrypt = util.promisify(crypto.scrypt);
@ -46,7 +46,7 @@ export default new class {
tmp = "items.id not in (select item_id from tags_assign group by item_id)"; tmp = "items.id not in (select item_id from tags_assign group by item_id)";
break; break;
case 3: // all case 3: // all
tmp = "1 = 1"; tmp = "";
break; break;
default: // sfw default: // sfw
tmp = "items.id in (select item_id from tags_assign where tag_id = 1 group by item_id)"; tmp = "items.id in (select item_id from tags_assign where tag_id = 1 group by item_id)";
@ -73,26 +73,10 @@ export default new class {
// async funcs // async funcs
async countf0cks() { async countf0cks() {
const tagged = (await db` const tagged = (await sql("items").whereRaw("id in (select item_id from tags_assign group by item_id)").count("* as total"))[0].total;
select count(*) as total const untagged = (await sql("items").whereRaw("id not in (select item_id from tags_assign group by item_id)").count("* as total"))[0].total;
from "items" const sfw = (await sql("items").whereRaw("id in (select item_id from tags_assign where tag_id = 1 group by item_id)").count("* as total"))[0].total;
where id in (select item_id from tags_assign group by item_id) const nsfw = (await sql("items").whereRaw("id in (select item_id from tags_assign where tag_id = 2 group by item_id)").count("* as total"))[0].total;
`)[0].total;
const untagged = (await db`
select count(*) as total
from "items"
where id not in (select item_id from tags_assign group by item_id)
`)[0].total;
const sfw = (await db`
select count(*) as total
from "items"
where id in (select item_id from tags_assign where tag_id = 1 group by item_id)
`)[0].total;
const nsfw = (await db`
select count(*) as total
from "items"
where id in (select item_id from tags_assign where tag_id = 2 group by item_id)
`)[0].total;
return { return {
tagged, tagged,
untagged, untagged,
@ -122,14 +106,12 @@ export default new class {
return next(); return next();
}; };
async getTags(itemid) { async getTags(itemid) {
const tags = await db` const tags = await sql("tags_assign")
select "tags".id, "tags".tag, "tags".normalized, "user".user .select("tags.id", "tags.tag", "tags.normalized", "user.user")
from "tags_assign" .leftJoin("tags", "tags.id", "tags_assign.tag_id")
left join "tags" on "tags".id = "tags_assign".tag_id .leftJoin("user", "user.id", "tags_assign.user_id")
left join "user" on "user".id = "tags_assign".user_id .where("tags_assign.item_id", +itemid)
where "tags_assign".item_id = ${+itemid} .orderBy("tags.id", "asc");
order by "tags".id asc
`;
for(let t = 0; t < tags.length; t++) { for(let t = 0; t < tags.length; t++) {
if(tags[t].tag.startsWith(">")) if(tags[t].tag.startsWith(">"))
tags[t].badge = "badge-greentext badge-light"; tags[t].badge = "badge-greentext badge-light";

View File

@ -10,6 +10,6 @@ export default new Proxy({}, {
level: prop, level: prop,
message: msg, message: msg,
timestamp: timestamp timestamp: timestamp
}) + "\n")// && }) + "\n") &&
//console.log(timestamp, prop, msg) console.log(timestamp, prop, msg)
}); });

View File

@ -1,4 +1,4 @@
import db from "../sql.mjs"; import sql from "../sql.mjs";
import lib from "../lib.mjs"; import lib from "../lib.mjs";
import cfg from "../config.mjs"; import cfg from "../config.mjs";
import fs from "fs"; import fs from "fs";
@ -26,46 +26,43 @@ export default {
message: "nope." message: "nope."
}; };
total = await db` total = (await sql("items")
select count(*) as total .innerJoin(
from items sql("tags")
inner join ( .select("tags_assign.item_id", "tags.tag")
select tags_assign.item_id, tags.tag .leftJoin("tags_assign", "tags_assign.tag_id", "tags.id")
from tags .where("tags.tag", "ilike", "%"+tag+"%")
left join tags_assign on tags_assign.tag_id = tags.id .groupBy("tags_assign.item_id", "tags.tag")
where tags.tag ilike ${'%' + (tag ? tag : '') + '%'} .as("st"),
group by tags_assign.item_id, tags.tag "st.item_id", "items.id"
) as st on st.item_id = items.id )
where ${db.unsafe(modequery)} .whereRaw(modequery)
group by st.tag, st.item_id`; .groupBy('st.tag', 'st.item_id')
.count("* as total")
total = total?.length; )?.length;
} }
else { else {
if(!o.fav) { if(!o.fav) {
total = await db` total = (await sql("items")
select count(*) as total .whereRaw(modequery)
from items .andWhere("items.mime", "ilike", smime)
where ${db.unsafe(modequery)} .andWhere("items.username", "ilike", user ? user : "%")
and items.mime ilike ${smime} .count("* as total")
and items.username ilike ${user ? user : '%'} )[0]?.total;
`;
total = total[0].total;
} }
else { else {
total = await db` total = (await sql("favorites")
select count(*) as total .select('items.id', 'items.mime')
from "favorites" .leftJoin('user', 'user.id', 'favorites.user_id')
left join "user" on "user".id = "favorites".user_id .leftJoin('tags_assign', 'tags_assign.item_id', 'favorites.item_id')
left join "tags_assign" on "tags_assign".item_id = "favorites".item_id .leftJoin('tags', 'tags.id', 'tags_assign.tag_id')
left join "tags" on "tags".id = "tags_assign".tag_id .leftJoin('items', 'items.id', 'favorites.item_id')
left join "items" on "items".id = "favorites".item_id .whereRaw(modequery)
where ${db.unsafe(modequery)} .andWhere('items.mime', 'ilike', smime)
and "items".mime ilike ${smime} .andWhere('user.user', 'ilike', user)
and "user".user ilike ${user} .groupBy('items.id')
group by "items".id .count('* as total')
`; )[0]?.total;
total = total[0].total;
} }
} }
@ -82,66 +79,45 @@ export default {
let rows; let rows;
if(!o.fav) { if(!o.fav) {
rows = db` rows = sql("items")
select "items".id, "items".mime, "tags_assign".tag_id .select("items.id", "items.mime", "tags_assign.tag_id")
from "items" .joinRaw("left join tags_assign on tags_assign.item_id = items.id and (tags_assign.tag_id = 1 or tags_assign.tag_id = 2)")
left join "tags_assign" on "tags_assign".item_id = "items".id and ("tags_assign".tag_id = 1 or "tags_assign".tag_id = 2) .whereRaw(modequery)
${tag .andWhere("items.mime", "ilike", smime)
? db` .andWhere("items.username", "ilike", user ? user : "%")
inner join ( .orderBy("items.id", "desc")
select "tags_assign".item_id, "tags".tag .offset(offset)
from "tags" .limit(cfg.websrv.eps);
left join "tags_assign" on "tags_assign".tag_id = "tags".id
where "tags".tag ilike ${'%' + tag + '%'}
group by "tags_assign".item_id, "tags".tag
) as st on st.item_id = "items".id
`
: db``
}
where ${db.unsafe(modequery)}
and "items".mime ilike ${smime}
and "items".username ilike ${user ? user : '%'}
${tag
? db`group by st.item_id, "items".id, "tags_assign".tag_id`
: db``
}
order by "items".id desc
offset ${offset}
limit ${cfg.websrv.eps}
`;
} }
else { else {
rows = db` rows = sql("favorites")
select "items".id, "items".mime, ta.tag_id .select('items.id', 'items.mime', 'ta.tag_id')
from "favorites" .leftJoin('user', 'user.id', 'favorites.user_id')
left join "user" on "user".id = "favorites".user_id .leftJoin('tags_assign', 'tags_assign.item_id', 'favorites.item_id')
left join "tags_assign" on "tags_assign".item_id = "favorites".item_id .leftJoin('tags', 'tags.id', 'tags_assign.tag_id')
left join "tags" on "tags".id = "tags_assign".tag_id .leftJoin('items', 'items.id', 'favorites.item_id')
left join "items" on "items".id = "favorites".item_id .joinRaw("left join tags_assign as ta on ta.item_id = items.id and (ta.tag_id = 1 or ta.tag_id = 2)")
left join "tags_assign" as ta on ta.item_id = "items".id and (ta.tag_id = 1 or ta.tag_id = 2) .whereRaw(modequery)
${ tag .andWhere('items.mime', 'ilike', smime)
? db` .andWhere('user.user', 'ilike', user)
inner join ( .orderBy('items.id', 'desc')
select "tags_assign".item_id, "tags".tag .groupBy('items.id', 'ta.tag_id')
from "tags" .offset(offset)
left join "tags_assign" on "tags_assign".tag_id = "tags".id .limit(cfg.websrv.eps);
where "tags".tag ilike ${'%' + tag + '%'} }
group by "tags_assign".item_id, "tags".tag
) as st on st.item_id = "items".id` if(tag) {
: db`` rows = rows
} .innerJoin(
where ${db.unsafe(modequery)} sql("tags")
and "items".mime ilike ${smime} .select("tags_assign.item_id", "tags.tag")
and "user".user ilike ${user} .leftJoin("tags_assign", "tags_assign.tag_id", "tags.id")
${tag .where("tags.tag", "ilike", "%"+tag+"%")
? db`group by st.item_id, "items".id, "tags_assign".tag_id` .groupBy("tags_assign.item_id", "tags.tag")
: db`` .as("st"),
} "st.item_id", "items.id"
group by "items".id, ta.tag_id )
order by "items".id desc .groupBy('st.item_id', 'items.id', 'tags_assign.tag_id');
offset ${offset}
limit ${cfg.websrv.eps}
`;
} }
rows = await rows; rows = await rows;
@ -201,66 +177,39 @@ export default {
let items; let items;
if(o.fav) { if(o.fav) {
items = db` items = sql('favorites')
select "items".* .select('items.*')
from "favorites" .leftJoin('items', 'items.id', 'favorites.item_id')
left join "items" on "items".id = "favorites".item_id .leftJoin('user', 'user.id', 'favorites.user_id')
left join "user" on "user".id = "favorites".user_id .whereRaw(modequery)
${ tag .andWhere('user.user', 'ilike', user)
? db`
inner join (
select "tags_assign".item_id, "tags".tag
from "tags"
left join "tags_assign" on "tags_assign".tag_id = "tags".id
where "tags".tag ilike ${'%' + tag + '%'}
group by "tags_assign".item_id, "tags".tag
) as st on st.item_id = "items".id`
: db``
}
where ${db.unsafe(modequery)}
and "user".user ilike ${user}
${ mime
? db`and "items".mime ilike ${mime + '/%'}`
: db``
}
${ tag
? db`group by st.tag, st.item_id, "items".id`
: db`group by "items".id, "favorites".user_id, "favorites".item_id, "user".id`
}
`;
} }
else { else {
items = db` items = sql("items")
select * .select("*")
from "items" .orderBy("items.id", "desc")
${tag .whereRaw(modequery);
? db`
inner join (
select "tags_assign".item_id, "tags".tag
from "tags"
left join "tags_assign" on "tags_assign".tag_id = "tags".id
where "tags".tag ilike ${'%' + tag + '%'}
group by "tags_assign".item_id, "tags".tag
) as st on st.item_id = "items".id`
: db``
}
where ${db.unsafe(modequery)}
${ user
? db`and "items".username ilike ${'%' + user + '%'}`
: db``
}
${ mime
? db`and "items".mime ilike ${mime + '/%'}`
: db``
}
${ tag
? db`group by st.item_id, "items".id, "tags_assign".tag_id`
: db`group by "items".id`
}
order by "items".id desc
`;
} }
if(tag) {
items = items.innerJoin(
sql("tags")
.select("tags_assign.item_id", "tags.tag")
.leftJoin("tags_assign", "tags_assign.tag_id", "tags.id")
.where("tags.tag", "ilike", "%"+tag+"%")
.groupBy("tags.tag", "tags_assign.item_id")
.as("st"),
"st.item_id", "items.id"
)
.groupBy('st.tag', 'st.item_id', 'items.id');
}
else
items = items.groupBy('items.id');
if(user && !o.fav)
items = items.andWhere("items.username", "ilike", "%" + user + "%");
if(mime)
items = items.andWhere("items.mime", "ilike", mime + "/%");
items = await items; items = await items;
if(tag) if(tag)
@ -279,13 +228,11 @@ export default {
const tags = await lib.getTags(itemid); const tags = await lib.getTags(itemid);
const cheat = [...new Set(items.slice(Math.max(0, item - 3), item + 4).map(i => i.id))]; const cheat = [...new Set(items.slice(Math.max(0, item - 3), item + 4).map(i => i.id))];
const link = lib.genLink({ user, tag, mime, type: o.fav ? 'favs' : 'f0cks' }); const link = lib.genLink({ user, tag, mime, type: o.fav ? 'favs' : 'f0cks' });
const favorites = await db` const favorites = await sql('favorites')
select "user".user, "user_options".avatar .select('user.user', 'user_options.avatar')
from "favorites" .leftJoin('user', 'user.id', 'favorites.user_id')
left join "user" on "user".id = "favorites".user_id .leftJoin('user_options', 'user_options.user_id', 'favorites.user_id')
left join "user_options" on "user_options".user_id = "favorites".user_id .where('favorites.item_id', itemid);
where "favorites".item_id = ${itemid}
`;
let coverart = true; let coverart = true;
try { try {
@ -339,66 +286,45 @@ export default {
const user = o.user ? decodeURI(o.user) : null; const user = o.user ? decodeURI(o.user) : null;
const tag = lib.parseTag(o.tag ?? null); const tag = lib.parseTag(o.tag ?? null);
const mime = (o.mime ?? ""); const mime = (o.mime ?? "");
const itemid = +(o.itemid ?? 404);
const smime = cfg.allowedMimes.includes(mime) ? mime + "/%" : mime === "" ? "%" : "%";
const modequery = mime == "audio" ? lib.getMode(0) : lib.getMode(o.mode ?? 0); const modequery = mime == "audio" ? lib.getMode(0) : lib.getMode(o.mode ?? 0);
let item; let item;
if(o.fav) { // dood lol if(o.fav) {
item = db` item = sql("favorites")
select "items".* .select('items.*')
from "favorites" .leftJoin('items', 'items.id', 'favorites.item_id')
left join "items" on "items".id = "favorites".item_id .leftJoin('user', 'user.id', 'favorites.user_id')
left join "user" on "user".id = "favorites".user_id .whereRaw(modequery)
${ tag .orderByRaw("random()")
? db` .andWhere('user.user', 'ilike', user);
inner join (
select "tags_assign".item_id, "tags".tag
from "tags"
left join "tags_assign" on "tags_assign".tag_id = "tags".id
where "tags".tag ilike ${'%' + tag + '%'}
group by "tags_assign".item_id, "tags".tag
) as st on st.item_id = "items".id`
: db``
}
where ${db.unsafe(modequery)}
and "user".user ilike ${user}
${ mime
? db`and "items".mime ilike ${mime + '/%'}`
: db``
}
order by random()
limit 1
`;
} }
else { else {
item = db` item = sql("items")
select * .select("*")
from "items" .orderByRaw("random()")
${ tag .whereRaw(modequery);
? db`
inner join (
select "tags_assign".item_id, "tags".tag
from "tags"
left join "tags_assign" on "tags_assign".tag_id = "tags".id
where "tags".tag ilike ${'%' + tag + '%'}
group by "tags_assign".item_id, "tags".tag
) as st on st.item_id = "items".id`
: db``
}
where ${db.unsafe(modequery)}
${ user
? db`and "items".username ilike ${'%' + user + '%'}`
: db``
}
${ mime
? db`and "items".mime ilike ${mime + '/%'}`
: db``
}
order by random()
limit 1
`;
} }
if(tag) {
item = item.innerJoin(
sql("tags")
.select("tags_assign.item_id", "tags.tag")
.leftJoin("tags_assign", "tags_assign.tag_id", "tags.id")
.where("tags.tag", "ilike", "%"+tag+"%")
.groupBy("tags_assign.item_id", "tags.tag")
.as("st"),
"st.item_id", "items.id"
)
.groupBy('st.item_id', 'st.tag', 'items.id');
}
if(user)
item = item.andWhere("username", "ilike", "%" + user + "%");
if(mime)
item = item.andWhere("mime", "ilike", mime + "/%");
item = await item; item = await item;
if(item.length === 0) { if(item.length === 0) {

View File

@ -1,4 +1,4 @@
import db from "../sql.mjs"; import sql from "../sql.mjs";
import lib from "../lib.mjs"; import lib from "../lib.mjs";
import { exec } from "child_process"; import { exec } from "child_process";
import search from "../routeinc/search.mjs"; import search from "../routeinc/search.mjs";
@ -24,26 +24,20 @@ export default (router, tpl) => {
}); });
router.post(/^\/login(\/)?$/, async (req, res) => { router.post(/^\/login(\/)?$/, async (req, res) => {
const user = await db` const user = await sql("user").where("login", req.post.username.toLowerCase()).limit(1);
select *
from "user"
where "login" = ${req.post.username.toLowerCase()}
limit 1
`;
if(user.length === 0) if(user.length === 0)
return res.reply({ body: "user doesn't exist or wrong password" }); return res.reply({ body: "user doesn't exist or wrong password" });
if(!(await lib.verify(req.post.password, user[0].password))) if(!(await lib.verify(req.post.password, user[0].password)))
return res.reply({ body: "user doesn't exist or wrong password" }); return res.reply({ body: "user doesn't exist or wrong password" });
const stamp = ~~(Date.now() / 1e3); const stamp = ~~(Date.now() / 1e3);
await db` await sql("user_sessions") // delete unused sessions
delete from user_sessions .where('last_action', '<=', (Date.now() - 6048e5))
where last_action <= ${(Date.now() - 6048e5)} .andWhere('kmsi', 0)
and kmsi = 0 .del();
`;
const session = lib.md5(lib.createID()); const session = lib.md5(lib.createID());
const blah = { await sql("user_sessions").insert({
user_id: user[0].id, user_id: user[0].id,
session: lib.md5(session), session: lib.md5(session),
browser: req.headers["user-agent"], browser: req.headers["user-agent"],
@ -51,13 +45,7 @@ export default (router, tpl) => {
last_used: stamp, last_used: stamp,
last_action: "/login", last_action: "/login",
kmsi: typeof req.post.kmsi !== 'undefined' ? 1 : 0 kmsi: typeof req.post.kmsi !== 'undefined' ? 1 : 0
}; });
await db`
insert into "user_sessions" ${
db(blah, 'user_id', 'session', 'browser', 'created_at', 'last_used', 'last_action', 'kmsi')
}
`;
return res.writeHead(301, { return res.writeHead(301, {
"Cache-Control": "no-cache, public", "Cache-Control": "no-cache, public",
@ -67,18 +55,11 @@ export default (router, tpl) => {
}); });
router.get(/^\/logout$/, auth, async (req, res) => { router.get(/^\/logout$/, auth, async (req, res) => {
const usersession = await db` const usersession = await sql("user_sessions").where("id", req.session.sess_id);
select *
from "user_sessions"
where id = ${+req.session.sess_id}
`;
if(usersession.length === 0) if(usersession.length === 0)
return res.reply({ body: "nope 2" }); return res.reply({ body: "nope 2" });
await db` await sql("user_sessions").where("id", req.session.sess_id).del();
delete from "user_sessions"
where id = ${+req.session.sess_id}
`;
return res.writeHead(301, { return res.writeHead(301, {
"Cache-Control": "no-cache, public", "Cache-Control": "no-cache, public",
"Set-Cookie": "session=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT", "Set-Cookie": "session=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT",
@ -105,12 +86,10 @@ export default (router, tpl) => {
}); });
router.get(/^\/admin\/sessions(\/)?$/, auth, async (req, res) => { router.get(/^\/admin\/sessions(\/)?$/, auth, async (req, res) => {
const rows = await db` const rows = await sql("user_sessions")
select "user_sessions".*, "user".user .leftJoin("user", "user.id", "user_sessions.user_id")
from "user_sessions" .select("user_sessions.*", "user.user")
left join "user" on "user".id = "user_sessions".user_id .orderBy("user_sessions.last_used", "desc");
order by "user_sessions".last_used desc
`;
res.reply({ res.reply({
body: tpl.render("admin/sessions", { body: tpl.render("admin/sessions", {
@ -129,22 +108,17 @@ export default (router, tpl) => {
if(tag.startsWith('src:')) { if(tag.startsWith('src:')) {
tag = tag.substring(4); tag = tag.substring(4);
ret = await db` ret = await sql('items')
select * .where('src', 'ilike', '%'+tag+'%')
from "items" .limit(500);
where src ilike ${'%' + tag + '%'}
limit 500
`;
} }
else { else {
rows = await db` rows = await sql("tags")
select "items".id, "items".username, "tags".tag .select("items.id", "items.username", "tags.tag")
from "tags" .leftJoin("tags_assign", "tags_assign.tag_id", "tags.id")
left join "tags_assign" on "tags_assign".tag_id = "tags".id .leftJoin("items", "items.id", "tags_assign.item_id")
left join "items" on "items".id = "tags_assign".item_id .where("tags.tag", "like", '%'+tag+'%')
where "tags".tag ilike ${'%' + tag + '%'} .limit(500);
limit 500
`;
ret = search(rows, tag); ret = search(rows, tag);
} }
} }

View File

@ -1,4 +1,4 @@
import db from '../../sql.mjs'; import sql from '../../sql.mjs';
import lib from '../../lib.mjs'; import lib from '../../lib.mjs';
import search from '../../routeinc/search.mjs'; import search from '../../routeinc/search.mjs';
@ -13,14 +13,11 @@ export default router => {
const user = req.url.split[3] === "user" ? req.url.split[4] : "%"; const user = req.url.split[3] === "user" ? req.url.split[4] : "%";
const mime = (allowedMimes.filter(n => req.url.split[3]?.startsWith(n))[0] ? req.url.split[3] : "") + "%"; const mime = (allowedMimes.filter(n => req.url.split[3]?.startsWith(n))[0] ? req.url.split[3] : "") + "%";
const rows = await db` const rows = await sql("items")
select * .orderByRaw("rand()")
from "items" .limit(1)
where mime ilike ${mime} .where("mime", "ilike", mime)
and username ilike ${user} .andWhere("username", "ilike", user);
order by random()
limit 1
`;
return res.json({ return res.json({
success: rows.length > 0, success: rows.length > 0,
@ -32,13 +29,7 @@ export default router => {
let eps = 100; let eps = 100;
let id = +req.url.split[3]; let id = +req.url.split[3];
const rows = await db` const rows = await sql("items").where("id", "<", id).orderBy("id", "desc").limit(eps);
select *
from "items"
where id < ${+id}
order by id desc
limit ${+eps}
`;
const items = { const items = {
items: rows, items: rows,
@ -54,26 +45,9 @@ export default router => {
group.get(/\/item\/[0-9]+$/, async (req, res) => { group.get(/\/item\/[0-9]+$/, async (req, res) => {
const id = +req.url.split[3]; const id = +req.url.split[3];
const item = await db` const item = await sql("items").where("id", id).limit(1);
select * const next = await sql("items").select("id").where("id", ">", id).orderBy("id").limit(1);
from "items" const prev = await sql("items").select("id").where("id", "<", id).orderBy("id", "desc").limit(1);
where id = ${+id}
limit 1
`;
const next = await db`
select id
from "items"
where id > ${+id}
order by id
limit 1
`;
const prev = await db`
select id
from "items"
where id < ${+id}
order by id desc
limit 1
`;
if(item.length === 0) { if(item.length === 0) {
return res.json({ return res.json({
@ -100,13 +74,11 @@ export default router => {
const user = req.url.split[3]; const user = req.url.split[3];
const eps = +req.url.split[4] || 50; const eps = +req.url.split[4] || 50;
const rows = db` const rows = await sql("items")
select id, mime, size, src, stamp, userchannel, username, usernetwork .select("id", "mime", "size", "src", "stamp", "userchannel", "username", "usernetwork")
from "items" .where("username", user)
where username = ${user} .orderBy("stamp", "desc")
order by stamp desc .limit(eps);
limit ${+eps}
`;
return res.json({ return res.json({
success: rows.length > 0, success: rows.length > 0,
@ -137,12 +109,11 @@ export default router => {
}, 405); // method not allowed }, 405); // method not allowed
} }
const tmptag = (await db` const tmptag = (
select * await sql('tags')
from "tags" .where('tag', tagname)
where tag = ${tagname} .limit(1)
limit 1 )[0];
`)[0];
if(!tmptag) { if(!tmptag) {
return res.json({ return res.json({
@ -151,15 +122,13 @@ export default router => {
}, 404); // not found }, 404); // not found
} }
const q = (await db` const q = (
update "tags" set ${ await sql('tags')
db({ .update({
tag: newtag tag: newtag
}, 'tag') }, [ 'tag', 'normalized' ])
} .where('tag', tagname)
where tag = ${tagname} )?.[0];
returning *
`)?.[0];
return res.json(q, tagname === newtag ? 200 : 201); // created (modified) return res.json(q, tagname === newtag ? 200 : 201); // created (modified)
}); });
@ -178,15 +147,13 @@ export default router => {
} }
try { try {
const q = await db` const q = await sql('tags')
select tag, count(tags_assign.tag_id) as tagged .select('tag', sql.raw('count(tags_assign.tag_id) as tagged'))
from "tags" .leftJoin('tags_assign', 'tags_assign.tag_id', 'tags.id')
left join "tags_assign" on "tags_assign".tag_id = "tags".id .whereRaw("normalized like '%' || slugify(?) || '%'", [ searchString ])
where normalized like '%' || slugify(${searchString}) || '%' .groupBy('tags.id')
group by "tags".id .orderBy('tagged', 'desc')
order by tagged desc .limit(15);
limit 15
`;
reply.success = true; reply.success = true;
reply.suggestions = search(q, searchString); reply.suggestions = search(q, searchString);
} catch(err) { } catch(err) {
@ -205,10 +172,7 @@ export default router => {
} }
const postid = +req.post.postid; const postid = +req.post.postid;
await db` await sql("items").where("id", postid).del();
delete from "items"
where id = ${+postid}
`;
res.json({ res.json({
success: true success: true
@ -218,39 +182,25 @@ export default router => {
group.post(/\/admin\/togglefav$/, lib.auth, async (req, res) => { group.post(/\/admin\/togglefav$/, lib.auth, async (req, res) => {
const postid = +req.post.postid; const postid = +req.post.postid;
let favs = await db` let favs = await sql('favorites').select('user_id').where('item_id', postid);
select user_id
from "favorites"
where item_id = ${+postid}
`;
if(Object.values(favs).filter(u => u.user_id === req.session.id)[0]) { if(Object.values(favs).filter(u => u.user_id === req.session.id)[0]) {
// del fav // del fav
await db` await sql('favorites').where('user_id', req.session.id).andWhere('item_id', postid).del();
delete from "favorites"
where user_id = ${+req.session.id}
and item_id = ${+postid}
`;
} }
else { else {
// add fav // add fav
await db` await sql('favorites').insert({
insert into "favorites" ${ item_id: postid,
db({ user_id: req.session.id
item_id: +postid, });
user_id: +req.session.id
}, 'item_id', 'user_id')
}
`;
} }
favs = await db` favs = await sql('favorites')
select "user".user, "user_options".avatar .select('user.user', 'user_options.avatar')
from "favorites" .leftJoin('user', 'user.id', 'favorites.user_id')
left join "user" on "user".id = "favorites".user_id .leftJoin('user_options', 'user_options.user_id', 'favorites.user_id')
left join "user_options" on "user_options".user_id = "favorites".user_id .where('favorites.item_id', postid);
where "favorites".item_id = ${+postid}
`;
return res.json({ return res.json({
success: true, success: true,

View File

@ -1,4 +1,4 @@
import db from '../../sql.mjs'; import sql from '../../sql.mjs';
import lib from '../../lib.mjs'; import lib from '../../lib.mjs';
export default router => { export default router => {
@ -13,11 +13,11 @@ export default router => {
const avatar = +req.post.avatar; const avatar = +req.post.avatar;
const itemid = (await db` const itemid = (
select id await sql('items')
from "items" .select('id')
where id = ${+avatar} .where('id', avatar)
`)?.[0]?.id; )?.[0]?.id;
if(!itemid) { if(!itemid) {
return res.json({ return res.json({
@ -25,14 +25,11 @@ export default router => {
}, 404); // not found }, 404); // not found
} }
const q = await db` const q = await sql('user_options')
update "user_options" set ${ .update({
db({ avatar
avatar })
}, 'avatar') .where('user_id', req.session.id);
}
where user_id = ${+req.session.id}
`;
return res.json({ return res.json({
msg: q msg: q

View File

@ -1,4 +1,4 @@
import db from '../../sql.mjs'; import sql from '../../sql.mjs';
import lib from '../../lib.mjs'; import lib from '../../lib.mjs';
export default router => { export default router => {
@ -38,32 +38,22 @@ export default router => {
} }
try { try {
let tagid = (await db` let tagid = (
select id await sql("tags")
from "tags" .select("id")
where normalized = slugify(${tagname}) .whereRaw("normalized = slugify(?)", [ tagname ])
`)?.[0]?.id; )?.[0]?.id;
if(!tagid) { // create new tag if(!tagid) { // create new tag
tagid = (await db` tagid = (await sql("tags").returning("id").insert({
insert into "tags" ${ tag: tagname
db({ }))[0];
tag: tagname
})
}
returning id
`)[0].id;
} }
await sql("tags_assign").insert({
await db` tag_id: tagid,
insert into "tags_assign" ${ item_id: postid,
db({ user_id: req.session.id
tag_id: +tagid, });
item_id: +postid,
user_id: +req.session.id
})
}
`;
} catch(err) { } catch(err) {
return res.json({ return res.json({
success: false, success: false,
@ -93,24 +83,20 @@ export default router => {
if(!(await lib.getTags(postid)).filter(tag => [1,2].includes(tag.id)).length) { if(!(await lib.getTags(postid)).filter(tag => [1,2].includes(tag.id)).length) {
// insert // insert
await db` await sql('tags_assign').insert({
insert into "tags_assign" ${ item_id: postid,
db({ tag_id: 1,
item_id: +postid, user_id: req.session.id
tag_id: 1, });
user_id: +req.session.id
})
}
`;
} }
else { else {
// update // update
await db` await sql('tags_assign')
update "tags_assign" .update({
set tag_id = (array[2,1])[tag_id] tag_id: sql.raw('(array[2,1])[tag_id]')
where tag_id = any(array[1,2]) })
and item_id = ${+postid} .whereRaw('tag_id = any(array[1,2])')
`; .andWhere('item_id', postid);
} }
return res.json({ return res.json({
@ -143,16 +129,10 @@ export default router => {
}); });
} }
let q = await db` let q = sql("tags_assign").where("tag_id", tagid).andWhere("item_id", postid).del();
delete from "tags_assign" if(req.session.level < 50)
where tag_id = ${+tagid} q = q.andWhere("user_id", req.session.id);
and item_id = ${+postid} const reply = !!(await q);
${ req.session.level < 50
? db`and user_id = ${+req.session.id}`
: db``
}
`;
const reply = !!q;
return res.json({ return res.json({
success: reply, success: reply,

View File

@ -1,5 +1,5 @@
import cfg from "../config.mjs"; import cfg from "../config.mjs";
import db from "../sql.mjs"; import sql from "../sql.mjs";
import lib from "../lib.mjs"; import lib from "../lib.mjs";
import f0cklib from "../routeinc/f0cklib.mjs"; import f0cklib from "../routeinc/f0cklib.mjs";
@ -49,52 +49,37 @@ export default (router, tpl) => {
referer = referertmp.split("/").slice(3).join("/"); referer = referertmp.split("/").slice(3).join("/");
if(cfg.allowedModes[mode]) { if(cfg.allowedModes[mode]) {
const blah = { await sql("user_options")
user_id: req.session.id, .insert({
mode: mode, user_id: req.session.id,
theme: req.theme ?? "f0ck" mode: mode,
}; theme: req.theme ?? "f0ck"
})
await db` .onConflict("user_id")
insert into "user_options" ${ .merge();
db(blah, 'user_id', 'mode', 'theme')
}
on conflict ("user_id") do update set
mode = excluded.mode,
theme = excluded.theme,
user_id = excluded.user_id
`;
} }
res.redirect(`/${referer}`); res.redirect(`/${referer}`);
}); });
router.get(/^\/ranking$/, async (req, res) => { router.get(/^\/ranking$/, async (req, res) => {
try { try {
const list = await db` const list = await sql('tags_assign')
select .select('user.user', sql.raw('coalesce(user_options.avatar, 47319) as avatar'))
"user".user, .leftJoin('user', 'user.id', 'tags_assign.user_id')
coalesce("user_options".avatar, 47319) as avatar, .leftJoin('user_options', 'user_options.user_id', 'user.id')
count(distinct(tag_id, item_id)) as count .groupBy('user.user', 'user_options.avatar')
from "tags_assign" .orderBy('count', 'desc')
left join "user" on "user".id = "tags_assign".user_id .countDistinct('tag_id', 'item_id', { as: 'count' });
left join "user_options" on "user_options".user_id = "user".id
group by "user".user, "user_options".avatar
order by count desc
`;
const stats = await lib.countf0cks(); const stats = await lib.countf0cks();
const hoster = await db` const hoster = await sql.with('t', sql.raw("select split_part(substring(src, position('//' in src)+2), '/', 1) part from items"))
with t as ( .from('t')
select .select('t.part')
split_part(substring(src, position('//' in src)+2), '/', 1) part .count('t.part as c')
from items .groupBy('t.part')
) .orderBy('c', 'desc')
select t.part, count(t.part) as c .limit(20);
from t
group by t.part
order by c desc
limit 20
`;
res.reply({ res.reply({
body: tpl.render('ranking', { body: tpl.render('ranking', {

View File

@ -1,4 +1,4 @@
import db from "../../inc/sql.mjs"; import sql from "../../inc/sql.mjs";
const auth = async (req, res, next) => { const auth = async (req, res, next) => {
if(!req.session) if(!req.session)
@ -9,16 +9,9 @@ const auth = async (req, res, next) => {
export default (router, tpl) => { export default (router, tpl) => {
router.group(/^\/settings/, group => { router.group(/^\/settings/, group => {
group.get(/$/, auth, async (req, res) => { group.get(/$/, auth, async (req, res) => {
/*const sessions = await sql("user_sessions") const sessions = await sql("user_sessions")
.where("user_id", req.session.id) .where("user_id", req.session.id)
.orderBy("last_used", "desc");*/ .orderBy("last_used", "desc");
const sessions = await db`
select *
from user_sessions
where user_id = ${ +req.session.id }
order by last_used desc
`;
res.reply({ res.reply({
body: tpl.render('settings', { body: tpl.render('settings', {

View File

@ -1,11 +1,7 @@
//import knex from "knex"; import knex from "knex";
import postgres from "postgres";
import cfg from "./config.mjs"; import cfg from "./config.mjs";
/*export default knex({ export default knex({
client: 'pg', client: 'pgnative',
connection: cfg.sql connection: cfg.sql
});*/ });
//export const db = postgres(cfg.sql);
export default postgres(cfg.sql);

View File

@ -1,5 +1,7 @@
import { getLevel } from "../admin.mjs"; import { getLevel } from "../admin.mjs";
import fetch from "flumm-fetch"; import fetch from "flumm-fetch-cookies";
import sql from "../sql.mjs";
import vm from "vm"; import vm from "vm";
let maxoutput = 750; let maxoutput = 750;
@ -7,6 +9,7 @@ let context = vm.createContext({
e: null, e: null,
bot: null, bot: null,
admins: null, admins: null,
sql: sql,
fetch: fetch, fetch: fetch,
a: null, a: null,

View File

@ -1,5 +1,5 @@
import { promises as fs } from "fs"; import { promises as fs } from "fs";
import db from "../sql.mjs"; import sql from "../sql.mjs";
export default async bot => { export default async bot => {
@ -14,22 +14,14 @@ export default async bot => {
if(id <= 0) if(id <= 0)
return false; return false;
const f0ck = await db` const f0ck = await sql("items").select("dest").where("id", id).limit(1);
select dest
from "items"
where id = ${+id}
limit 1
`;
if(f0ck.length === 0) if(f0ck.length === 0)
return false; return false;
await fs.unlink(`./public/b/${f0ck[0].dest}`).catch(_=>{}); await fs.unlink(`./public/b/${f0ck[0].dest}`).catch(_=>{});
await fs.unlink(`./public/t/${id}`).catch(_=>{}); await fs.unlink(`./public/t/${id}`).catch(_=>{});
await db` await sql("items").where("id", id).del().limit(1);
delete from "items"
where id = ${+id}
`;
return id; return id;
}))).filter(d => d); }))).filter(d => d);

View File

@ -1,17 +1,14 @@
import fetch from "flumm-fetch"; import fetch from "flumm-fetch-cookies";
import { promises as fs } from "fs"; import { promises as fs } from "fs";
import { exec } from "child_process"; import { exec } from "child_process";
import cfg from "../config.mjs"; import cfg from "../config.mjs";
import db from "../sql.mjs"; import sql from "../sql.mjs";
import lib from "../lib.mjs"; import lib from "../lib.mjs";
/*const cleanTags = async () => { const cleanTags = async () => {
const tags = await db` const tags = await sql("tags")
select * .leftJoin("tags_assign", "tags_assign.tag_id", "tags.id")
from "tags" .whereNull("tags_assign.item_id");
left join "tags_assign" on "tags_assign".tag_id = "tags".id
where "tags_assign".item_id is null
`;
if(tags.length === 0) if(tags.length === 0)
return 0; return 0;
@ -26,7 +23,7 @@ import lib from "../lib.mjs";
}); });
await deleteTag.del(); await deleteTag.del();
return dtags; return dtags;
};*/ };
export default async bot => { export default async bot => {
@ -52,10 +49,7 @@ export default async bot => {
case "limit": case "limit":
return e.reply(`up to ${lib.formatSize(cfg.main.maxfilesize)} (${lib.formatSize(cfg.main.maxfilesize * cfg.main.adminmultiplier)} for admins)`); return e.reply(`up to ${lib.formatSize(cfg.main.maxfilesize)} (${lib.formatSize(cfg.main.maxfilesize * cfg.main.adminmultiplier)} for admins)`);
case "thumb": case "thumb":
const rows = await db` const rows = await sql("items").select("id");
select id
from "items"
`;
const dir = (await fs.readdir("./public/t")).filter(d => d.endsWith(".png")).map(e => +e.split(".")[0]); const dir = (await fs.readdir("./public/t")).filter(d => d.endsWith(".png")).map(e => +e.split(".")[0]);
const tmp = []; const tmp = [];
for(let row of rows) for(let row of rows)
@ -75,10 +69,10 @@ export default async bot => {
e.reply("hay hay patron, hemen!"); e.reply("hay hay patron, hemen!");
exec("sudo systemctl restart f0ck"); exec("sudo systemctl restart f0ck");
break; break;
/*case "cleanTags": case "cleanTags":
const tags = await cleanTags(); const tags = await cleanTags();
e.reply(tags + " tags removed"); e.reply(tags + " tags removed");
break;*/ break;
case "clearTmp": case "clearTmp":
await Promise.all((await fs.readdir("./tmp")).filter(d => d !== ".empty").map(async d => fs.unlink(`./tmp/${d}`))); await Promise.all((await fs.readdir("./tmp")).filter(d => d !== ".empty").map(async d => fs.unlink(`./tmp/${d}`)));
e.reply("cleared lol"); e.reply("cleared lol");

View File

@ -1,5 +1,5 @@
import cfg from "../config.mjs"; import cfg from "../config.mjs";
import db from "../sql.mjs"; import sql from "../sql.mjs";
import lib from "../lib.mjs"; import lib from "../lib.mjs";
const regex = /(https\:\/\/f0ck\.me|http\:\/\/fockmoonsb24iczs7odozzy5uktlzbcgp337nabrgffzxv5ihabgpvyd\.onion)(\/(video|image|audio))?\/(\d+|(?:b\/)(\w{8})\.(jpg|webm|gif|mp4|png|mov|mp3|ogg|flac))/gi; const regex = /(https\:\/\/f0ck\.me|http\:\/\/fockmoonsb24iczs7odozzy5uktlzbcgp337nabrgffzxv5ihabgpvyd\.onion)(\/(video|image|audio))?\/(\d+|(?:b\/)(\w{8})\.(jpg|webm|gif|mp4|png|mov|mp3|ogg|flac))/gi;
@ -12,15 +12,14 @@ export default async bot => {
active: true, active: true,
f: async e => { f: async e => {
const dat = e.message.match(regex)[0].split(/\//).pop(); const dat = e.message.match(regex)[0].split(/\//).pop();
const rows = await db` let query = sql("items").select("id", "mime", "size", "username", "userchannel", "usernetwork", "stamp");
select id, mime, size, username, userchannel, usernetwork, stamp
from "items"
${ dat.includes('.')
? db`where dest ilike ${'%' + dat + '%'}`
: db`where id = ${dat}`
}
`;
if(dat.includes("."))
query = query.where("dest", "like", `%${dat}%`);
else
query = query.where("id", dat);
const rows = await query;
if(rows.length === 0) if(rows.length === 0)
return e.reply("no f0cks given! lol D:"); return e.reply("no f0cks given! lol D:");

View File

@ -1,4 +1,4 @@
import db from "../sql.mjs"; import sql from "../sql.mjs";
import lib from "../lib.mjs"; import lib from "../lib.mjs";
import cfg from "../config.mjs"; import cfg from "../config.mjs";
@ -7,10 +7,10 @@ export default async bot => {
return [{ return [{
name: "f0ckrand", name: "f0ckrand",
call: /^gib f0ck/i, call: /^gib f0ck/i,
active: false, active: true,
f: async e => { f: async e => {
let args = e.args.slice(1); let args = e.args.slice(1);
/*let rows = sql("items").select("id", "username", "mime", "size"); let rows = sql("items").select("id", "username", "mime", "size");
for(let i = 0; i < args.length; i++) { for(let i = 0; i < args.length; i++) {
if(args[i].charAt(0) === "!") if(args[i].charAt(0) === "!")
@ -19,7 +19,7 @@ export default async bot => {
rows = rows.where("username", "ilike", args[i]); rows = rows.where("username", "ilike", args[i]);
} }
rows = await rows.orderByRaw("random()").limit(1);*/ rows = await rows.orderByRaw("random()").limit(1);
if(rows.length === 0) if(rows.length === 0)
return e.reply("nothing found, f0cker"); return e.reply("nothing found, f0cker");

View File

@ -1,8 +1,8 @@
import cfg from "../config.mjs"; import cfg from "../config.mjs";
import db from "../sql.mjs"; import sql from "../sql.mjs";
import lib from "../lib.mjs"; import lib from "../lib.mjs";
import { getLevel } from "../admin.mjs"; import { getLevel } from "../admin.mjs";
import fetch from "flumm-fetch"; import fetch from "flumm-fetch-cookies";
import fs from "fs"; import fs from "fs";
import { exec as _exec } from "child_process"; import { exec as _exec } from "child_process";
@ -45,18 +45,12 @@ export default async bot => {
links.forEach(async link => { links.forEach(async link => {
// check repost (link) // check repost (link)
const q_repost = await db` const q_repost = await sql("items").select("id").where("src", link);
select id
from "items"
where src = ${link}
`;
if(q_repost.length > 0) if(q_repost.length > 0)
return e.reply(`repost motherf0cker (link): ${cfg.main.url}/${q_repost[0].id}`); return e.reply(`repost motherf0cker (link): ${cfg.main.url}/${q_repost[0].id}`);
// generate uuid // generate uuid
const uuid = (await db` const uuid = (await sql.select(sql.raw("gen_random_uuid() as uuid")))[0].uuid.substring(0, 8);
select gen_random_uuid() as uuid
`)[0].uuid.substring(0, 8);
const maxfilesize = (getLevel(e.user).level > 50 ? cfg.main.maxfilesize * cfg.main.adminmultiplier : cfg.main.maxfilesize) / 1024; const maxfilesize = (getLevel(e.user).level > 50 ? cfg.main.maxfilesize * cfg.main.adminmultiplier : cfg.main.maxfilesize) / 1024;
@ -114,40 +108,26 @@ export default async bot => {
} }
// check repost (checksum) // check repost (checksum)
const q_repostc = await db` const q_repostc = await sql("items").select("id").where("checksum", checksum);
select id
from "items"
where checksum = ${checksum}
`;
if(q_repostc.length > 0) if(q_repostc.length > 0)
return e.reply(`repost motherf0cker (checksum): ${cfg.main.url}/${q_repostc[0].id}`); return e.reply(`repost motherf0cker (checksum): ${cfg.main.url}/${q_repostc[0].id}`);
await fs.promises.copyFile(`./tmp/${filename}`, `./public/b/${filename}`); await fs.promises.copyFile(`./tmp/${filename}`, `./public/b/${filename}`);
await fs.promises.unlink(`./tmp/${filename}`).catch(_=>{}); await fs.promises.unlink(`./tmp/${filename}`).catch(_=>{});
await db` await sql("items").insert({
insert into items ${ src: e.photo ? "" : link,
db({ dest: filename,
src: e.photo ? "" : link, mime: mime,
dest: filename, size: size,
mime: mime, checksum: checksum,
size: size, username: e.user.nick || e.user.username,
checksum: checksum, userchannel: e.channel,
username: e.user.nick || e.user.username, usernetwork: e.network,
userchannel: e.channel, stamp: ~~(new Date() / 1000),
usernetwork: e.network, active: 1
stamp: ~~(new Date() / 1000), });
active: 1 const itemid = (await sql('items').where('dest', filename).limit(1))[0].id;
}, 'src', 'dest', 'mime', 'size', 'checksum', 'username', 'userchannel', 'usernetwork', 'stamp', 'active')
}
`;
const itemid = (await db`
select *
from "items"
where dest = ${filename}
limit 1
`)[0].id;
// generate thumbnail // generate thumbnail
try { try {
@ -204,15 +184,11 @@ export default async bot => {
} }
if(tag === 'sfw' || tag === 'nsfw') { if(tag === 'sfw' || tag === 'nsfw') {
await db` await sql("tags_assign").insert({
insert into "tags_assign" ${ tag_id: tag === "sfw" ? 1 : 2,
db({ item_id: itemid,
tag_id: tag === "sfw" ? 1 : 2, user_id: 7 // user: autotagger (ID: 7)
item_id: itemid, });
user_id: 7 // user: autotagger (ID: 7)
}, 'tag_id', 'item_id', 'user_id')
}
`;
} }
} catch(err) { } catch(err) {
console.error(err); console.error(err);

View File

@ -1,8 +1,12 @@
import db from "../sql.mjs"; import sql from "../sql.mjs";
import cfg from "../config.mjs"; import cfg from "../config.mjs";
import lib from "../lib.mjs";
import { getLevel } from "../admin.mjs"; import { getLevel } from "../admin.mjs";
const getTags = async itemid => await sql("tags_assign")
.leftJoin("tags", "tags.id", "tags_assign.tag_id")
.where("tags_assign.item_id", itemid)
.select("tags.id", "tags.tag");
export default async bot => { export default async bot => {
return [{ return [{
name: "tags show", name: "tags show",
@ -13,7 +17,7 @@ export default async bot => {
const id = +e.args[1]; const id = +e.args[1];
if(!id) if(!id)
return e.reply("lol no"); return e.reply("lol no");
const tags = (await lib.getTags(id)).map(t => t.tag); const tags = (await getTags(id)).map(t => t.tag);
if(tags.length === 0) if(tags.length === 0)
return e.reply(`item ${cfg.main.url}/${id} has no tags!`); return e.reply(`item ${cfg.main.url}/${id} has no tags!`);
return e.reply(`item ${cfg.main.url}/${id} is tagged as: ${tags.join(', ')}`); return e.reply(`item ${cfg.main.url}/${id} is tagged as: ${tags.join(', ')}`);
@ -28,7 +32,7 @@ export default async bot => {
if(!id) if(!id)
return e.reply("lol no"); return e.reply("lol no");
const tags = (await lib.getTags(id)).map(t => t.tag); const tags = (await getTags(id)).map(t => t.tag);
const newtags = (e.message.includes(",") const newtags = (e.message.includes(",")
? e.args.splice(2).join(" ").trim().split(",") ? e.args.splice(2).join(" ").trim().split(",")
@ -40,38 +44,26 @@ export default async bot => {
await Promise.all(newtags.map(async ntag => { await Promise.all(newtags.map(async ntag => {
try { try {
let tagid; let tagid;
const tag_exists = await db` const tag_exists = await sql("tags").select("id", "tag").where("tag", ntag);
select id, tag
from "tags"
where tag = ${ntag}
`;
if(tag_exists.length === 0) { // create new tag if(tag_exists.length === 0) { // create new tag
tagid = (await db` tagid = (await sql("tags").insert({
insert into "tags" ${ tag: ntag
db({ }))[0];
tag: ntag
}, 'tag')
}
`)[0];
} }
else { else {
tagid = tag_exists[0].id; tagid = tag_exists[0].id;
} }
return await db` return await sql("tags_assign").insert({
insert into "tags_assign" ${ tag_id: tagid,
db({ item_id: id,
tag_id: tagid, prefix: `${e.user.prefix}${e.channel}`
item_id: id, });
prefix: `${e.user.prefix}${e.channel}`
}, 'tag_id', 'item_id', 'prefix')
}
`;
} catch(err) { } catch(err) {
console.error(err); console.error(err);
} }
})); }));
const ntags = (await lib.getTags(id)).map(t => t.tag); const ntags = (await getTags(id)).map(t => t.tag);
if(ntags.length === 0) if(ntags.length === 0)
return e.reply(`item ${cfg.main.url}/${id} has no tags!`); return e.reply(`item ${cfg.main.url}/${id} has no tags!`);
return e.reply(`item ${cfg.main.url}/${id} is now tagged as: ${ntags.join(', ')}`); return e.reply(`item ${cfg.main.url}/${id} is now tagged as: ${ntags.join(', ')}`);
@ -86,7 +78,7 @@ export default async bot => {
if(!id) if(!id)
return e.reply("lol no"); return e.reply("lol no");
const tags = await lib.getTags(id); const tags = await getTags(id);
const removetags = (e.message.includes(",") const removetags = (e.message.includes(",")
? e.args.splice(2).join(" ").trim().split(",") ? e.args.splice(2).join(" ").trim().split(",")
@ -105,18 +97,12 @@ export default async bot => {
}; };
} }
const q = await db` let q = sql("tags_assign").where("tag_id", tagid).andWhere("item_id", id).del();
delete from "tags_assign" if(getLevel(e.user).level < 50)
where tag_id = ${+tagid} q = q.andWhere("prefix", `${e.user.prefix}${e.channel}`);
and item_id = ${+id}
${ getLevel(e.user.level < 50)
? db`and prefix = ${e.user.prefix + e.channel}`
: db``
}
`;
return { return {
success: !!q, success: !!(await q),
tag: rtag, tag: rtag,
tagid: tagid tagid: tagid
}; };
@ -124,7 +110,7 @@ export default async bot => {
e.reply(JSON.stringify(res)); e.reply(JSON.stringify(res));
const ntags = (await lib.getTags(id)).map(t => t.tag); const ntags = (await getTags(id)).map(t => t.tag);
if(ntags.length === 0) if(ntags.length === 0)
return e.reply(`item ${cfg.main.url}/${id} has no tags!`); return e.reply(`item ${cfg.main.url}/${id} has no tags!`);
return e.reply(`item ${cfg.main.url}/${id} is now tagged as: ${ntags.join(', ')}`); return e.reply(`item ${cfg.main.url}/${id} is now tagged as: ${ntags.join(', ')}`);

View File

@ -1,5 +1,5 @@
import cfg from "./inc/config.mjs"; import cfg from "./inc/config.mjs";
import db from "./inc/sql.mjs"; import sql from "./inc/sql.mjs";
import lib from "./inc/lib.mjs"; import lib from "./inc/lib.mjs";
import cuffeo from "cuffeo"; import cuffeo from "cuffeo";
import { promises as fs } from "fs"; import { promises as fs } from "fs";
@ -20,35 +20,35 @@ import flummpress from "flummpress";
bot: await new cuffeo(cfg.clients) bot: await new cuffeo(cfg.clients)
}; };
//console.time("loading"); console.time("loading");
const modules = { const modules = {
events: (await fs.readdir("./src/inc/events")).filter(f => f.endsWith(".mjs")), events: (await fs.readdir("./src/inc/events")).filter(f => f.endsWith(".mjs")),
trigger: (await fs.readdir("./src/inc/trigger")).filter(f => f.endsWith(".mjs")) trigger: (await fs.readdir("./src/inc/trigger")).filter(f => f.endsWith(".mjs"))
}; };
//console.timeLog("loading", "directories"); console.timeLog("loading", "directories");
const blah = (await Promise.all(Object.entries(modules).map(async ([dir, mods]) => ({ const blah = (await Promise.all(Object.entries(modules).map(async ([dir, mods]) => ({
[dir]: (await Promise.all(mods.map(async mod => { [dir]: (await Promise.all(mods.map(async mod => {
const res = await Promise.race([ const res = await Promise.race([
(await import(`./inc/${dir}/${mod}`)).default(self), (await import(`./inc/${dir}/${mod}`)).default(self),
new Promise((_, rej) => setTimeout(() => rej(false), timeout)) new Promise((_, rej) => setTimeout(() => rej(false), timeout))
]); ]);
//console.timeLog("loading", `${dir}/${mod}`); console.timeLog("loading", `${dir}/${mod}`);
return res; return res;
}))).flat(2) }))).flat(2)
})))).reduce((a, b) => ({...a, ...b})); })))).reduce((a, b) => ({...a, ...b}));
blah.events.forEach(event => { blah.events.forEach(event => {
//console.timeLog("loading", `registering event > ${event.name}`); console.timeLog("loading", `registering event > ${event.name}`);
self.bot.on(event.listener, event.f); self.bot.on(event.listener, event.f);
}); });
blah.trigger.forEach(trigger => { blah.trigger.forEach(trigger => {
//console.timeLog("loading", `registering trigger > ${trigger.name}`); console.timeLog("loading", `registering trigger > ${trigger.name}`);
self._trigger.set(trigger.name, new self.trigger(trigger)); self._trigger.set(trigger.name, new self.trigger(trigger));
}); });
//console.timeEnd("loading"); console.timeEnd("loading");
// websrv // websrv
@ -64,14 +64,12 @@ import flummpress from "flummpress";
req.theme = req.cookies.theme ?? 'f0ck'; req.theme = req.cookies.theme ?? 'f0ck';
if(req.cookies.session) { if(req.cookies.session) {
const user = await db` const user = await sql("user_sessions") // get user
select "user".id, "user".login, "user".user, "user".level, "user_sessions".id as sess_id, "user_options".* .select("user.id", "user.login", "user.user", "user.level", "user_sessions.id as sess_id", "user_options.*")
from "user_sessions" .where("user_sessions.session", lib.md5(req.cookies.session))
left join "user" on "user".id = "user_sessions".user_id .leftJoin("user", "user.id", "user_sessions.user_id")
left join "user_options" on "user_options".user_id = "user_sessions".user_id .leftJoin("user_options", "user_options.user_id", "user_sessions.user_id")
where "user_sessions".session = ${lib.md5(req.cookies.session)} .limit(1);
limit 1
`;
if(user.length === 0) { if(user.length === 0) {
return res.writeHead(307, { // delete session return res.writeHead(307, { // delete session
@ -82,33 +80,21 @@ import flummpress from "flummpress";
} }
req.session = user[0]; req.session = user[0];
await sql("user_sessions") // log last action
// log last action .update("last_used", ~~(Date.now() / 1e3))
await db` .update("last_action", req.url.pathname)
update "user_sessions" set ${ .update("browser", req.headers["user-agent"])
db({ .where("id", user[0].sess_id);
last_used: ~~(Date.now() / 1e3),
last_action: req.url.pathname,
browser: req.headers['user-agent']
}, 'last_used', 'last_action', 'browser')
}
where id = ${+user[0].sess_id}
`;
// update userprofile // update userprofile
await db` await sql("user_options")
insert into "user_options" ${ .insert({
db({ user_id: user[0].id,
user_id: +user[0].id, mode: user[0].mode ?? 0,
mode: user[0].mode ?? 0, theme: req.session.theme ?? "f0ck"
theme: req.session.theme ?? 'f0ck' })
}, 'user_id', 'mode', 'theme') .onConflict("user_id")
} .merge();
on conflict ("user_id") do update set
mode = excluded.mode,
theme = excluded.theme,
user_id = excluded.user_id
`;
} }
}); });