Merge pull request 'blah' (#13) from dev into master

Reviewed-on: #13
This commit is contained in:
Flummi 2022-04-03 04:11:30 +02:00
commit 373b620a0b
20 changed files with 695 additions and 1156 deletions

766
package-lock.json generated
View File

@ -1,56 +1,20 @@
{ {
"name": "f0ckv2", "name": "f0ckv2",
"version": "2.1.0", "version": "2.2.0",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "f0ckv2", "name": "f0ckv2",
"version": "2.1.0", "version": "2.2.0",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"cuffeo": "^1.0.7-3", "cuffeo": "^1.0.7-3",
"flumm-fetch-cookies": "^1.4.0", "flumm-fetch": "^1.0.1",
"flummpress": "^2.0.4", "flummpress": "^2.0.4",
"knex": "^0.95.15", "postgres": "^3.0.1"
"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",
@ -59,43 +23,6 @@
"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",
@ -117,400 +44,17 @@
"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/function-bind": { "node_modules/postgres": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
"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": {
"url": "https://github.com/sponsors/ljharb"
}
},
"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", "version": "3.0.2",
"resolved": "https://registry.npmjs.org/tarn/-/tarn-3.0.2.tgz", "resolved": "https://registry.npmjs.org/postgres/-/postgres-3.0.2.tgz",
"integrity": "sha512-51LAVKUSZSVfI05vjPESNc5vwqqZpbXCsU+/+wxlOrUjk2SnFTt97v9ZgQrD4YmxYW1Px6w2KjaDitCfkvgxMQ==", "integrity": "sha512-sHkEGAnPVqRclh5oIr9S9e/VNX0/MUb2PgS9bl/0wnI8WrHhzMmxqq/fAkMZKUUrC3Lfa4qaNh1dyDPH4Q8V0w==",
"engines": { "funding": {
"node": ">=8.0.0" "type": "individual",
} "url": "https://github.com/sponsors/porsager"
},
"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",
@ -519,29 +63,6 @@
"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",
@ -560,271 +81,10 @@
"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=="
}, },
"function-bind": { "postgres": {
"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/tarn/-/tarn-3.0.2.tgz", "resolved": "https://registry.npmjs.org/postgres/-/postgres-3.0.2.tgz",
"integrity": "sha512-51LAVKUSZSVfI05vjPESNc5vwqqZpbXCsU+/+wxlOrUjk2SnFTt97v9ZgQrD4YmxYW1Px6w2KjaDitCfkvgxMQ==" "integrity": "sha512-sHkEGAnPVqRclh5oIr9S9e/VNX0/MUb2PgS9bl/0wnI8WrHhzMmxqq/fAkMZKUUrC3Lfa4qaNh1dyDPH4Q8V0w=="
},
"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.1.0", "version": "2.2.0",
"description": "f0ck, kennste?", "description": "f0ck, kennste?",
"main": "index.mjs", "main": "index.mjs",
"scripts": { "scripts": {
@ -15,10 +15,8 @@
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"cuffeo": "^1.0.7-3", "cuffeo": "^1.0.7-3",
"flumm-fetch-cookies": "^1.4.0", "flumm-fetch": "^1.0.1",
"flummpress": "^2.0.4", "flummpress": "^2.0.4",
"knex": "^0.95.15", "postgres": "^3.0.1"
"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 sql from "./sql.mjs"; import db 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 = ""; tmp = "1 = 1";
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,10 +73,26 @@ export default new class {
// async funcs // async funcs
async countf0cks() { async countf0cks() {
const tagged = (await sql("items").whereRaw("id in (select item_id from tags_assign group by item_id)").count("* as total"))[0].total; const tagged = (await db`
const untagged = (await sql("items").whereRaw("id not in (select item_id from tags_assign group by item_id)").count("* as total"))[0].total; select count(*) as total
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; from "items"
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; where id in (select item_id from tags_assign group by item_id)
`)[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,
@ -106,12 +122,14 @@ export default new class {
return next(); return next();
}; };
async getTags(itemid) { async getTags(itemid) {
const tags = await sql("tags_assign") const tags = await db`
.select("tags.id", "tags.tag", "tags.normalized", "user.user") select "tags".id, "tags".tag, "tags".normalized, "user".user
.leftJoin("tags", "tags.id", "tags_assign.tag_id") from "tags_assign"
.leftJoin("user", "user.id", "tags_assign.user_id") left join "tags" on "tags".id = "tags_assign".tag_id
.where("tags_assign.item_id", +itemid) left join "user" on "user".id = "tags_assign".user_id
.orderBy("tags.id", "asc"); where "tags_assign".item_id = ${+itemid}
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 sql from "../sql.mjs"; import db 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,43 +26,46 @@ export default {
message: "nope." message: "nope."
}; };
total = (await sql("items") total = await db`
.innerJoin( select count(*) as total
sql("tags") from items
.select("tags_assign.item_id", "tags.tag") inner join (
.leftJoin("tags_assign", "tags_assign.tag_id", "tags.id") select tags_assign.item_id, tags.tag
.where("tags.tag", "ilike", "%"+tag+"%") from tags
.groupBy("tags_assign.item_id", "tags.tag") left join tags_assign on tags_assign.tag_id = tags.id
.as("st"), where tags.tag ilike ${'%' + (tag ? tag : '') + '%'}
"st.item_id", "items.id" group by tags_assign.item_id, tags.tag
) ) as st on st.item_id = items.id
.whereRaw(modequery) where ${db.unsafe(modequery)}
.groupBy('st.tag', 'st.item_id') group by st.tag, st.item_id`;
.count("* as total")
)?.length; total = total?.length;
} }
else { else {
if(!o.fav) { if(!o.fav) {
total = (await sql("items") total = await db`
.whereRaw(modequery) select count(*) as total
.andWhere("items.mime", "ilike", smime) from items
.andWhere("items.username", "ilike", user ? user : "%") where ${db.unsafe(modequery)}
.count("* as total") and items.mime ilike ${smime}
)[0]?.total; and items.username ilike ${user ? user : '%'}
`;
total = total[0].total;
} }
else { else {
total = (await sql("favorites") total = await db`
.select('items.id', 'items.mime') select count(*) as total
.leftJoin('user', 'user.id', 'favorites.user_id') from "favorites"
.leftJoin('tags_assign', 'tags_assign.item_id', 'favorites.item_id') left join "user" on "user".id = "favorites".user_id
.leftJoin('tags', 'tags.id', 'tags_assign.tag_id') left join "tags_assign" on "tags_assign".item_id = "favorites".item_id
.leftJoin('items', 'items.id', 'favorites.item_id') left join "tags" on "tags".id = "tags_assign".tag_id
.whereRaw(modequery) left join "items" on "items".id = "favorites".item_id
.andWhere('items.mime', 'ilike', smime) where ${db.unsafe(modequery)}
.andWhere('user.user', 'ilike', user) and "items".mime ilike ${smime}
.groupBy('items.id') and "user".user ilike ${user}
.count('* as total') group by "items".id
)[0]?.total; `;
total = total[0].total;
} }
} }
@ -79,45 +82,66 @@ export default {
let rows; let rows;
if(!o.fav) { if(!o.fav) {
rows = sql("items") rows = db`
.select("items.id", "items.mime", "tags_assign.tag_id") select "items".id, "items".mime, "tags_assign".tag_id
.joinRaw("left join tags_assign on tags_assign.item_id = items.id and (tags_assign.tag_id = 1 or tags_assign.tag_id = 2)") from "items"
.whereRaw(modequery) left join "tags_assign" on "tags_assign".item_id = "items".id and ("tags_assign".tag_id = 1 or "tags_assign".tag_id = 2)
.andWhere("items.mime", "ilike", smime) ${tag
.andWhere("items.username", "ilike", user ? user : "%") ? db`
.orderBy("items.id", "desc") inner join (
.offset(offset) select "tags_assign".item_id, "tags".tag
.limit(cfg.websrv.eps); 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 "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 = sql("favorites") rows = db`
.select('items.id', 'items.mime', 'ta.tag_id') select "items".id, "items".mime, ta.tag_id
.leftJoin('user', 'user.id', 'favorites.user_id') from "favorites"
.leftJoin('tags_assign', 'tags_assign.item_id', 'favorites.item_id') left join "user" on "user".id = "favorites".user_id
.leftJoin('tags', 'tags.id', 'tags_assign.tag_id') left join "tags_assign" on "tags_assign".item_id = "favorites".item_id
.leftJoin('items', 'items.id', 'favorites.item_id') left join "tags" on "tags".id = "tags_assign".tag_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 "items" on "items".id = "favorites".item_id
.whereRaw(modequery) left join "tags_assign" as ta on ta.item_id = "items".id and (ta.tag_id = 1 or ta.tag_id = 2)
.andWhere('items.mime', 'ilike', smime) ${ tag
.andWhere('user.user', 'ilike', user) ? db`
.orderBy('items.id', 'desc') inner join (
.groupBy('items.id', 'ta.tag_id') 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)}
if(tag) { and "items".mime ilike ${smime}
rows = rows and "user".user ilike ${user}
.innerJoin( ${tag
sql("tags") ? db`group by st.item_id, "items".id, "tags_assign".tag_id`
.select("tags_assign.item_id", "tags.tag") : db``
.leftJoin("tags_assign", "tags_assign.tag_id", "tags.id") }
.where("tags.tag", "ilike", "%"+tag+"%") group by "items".id, ta.tag_id
.groupBy("tags_assign.item_id", "tags.tag") order by "items".id desc
.as("st"), offset ${offset}
"st.item_id", "items.id" limit ${cfg.websrv.eps}
) `;
.groupBy('st.item_id', 'items.id', 'tags_assign.tag_id');
} }
rows = await rows; rows = await rows;
@ -177,38 +201,65 @@ export default {
let items; let items;
if(o.fav) { if(o.fav) {
items = sql('favorites') items = db`
.select('items.*') select "items".*
.leftJoin('items', 'items.id', 'favorites.item_id') from "favorites"
.leftJoin('user', 'user.id', 'favorites.user_id') left join "items" on "items".id = "favorites".item_id
.whereRaw(modequery) left join "user" on "user".id = "favorites".user_id
.andWhere('user.user', 'ilike', user) ${ tag
? 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 = sql("items") items = db`
.select("*") select *
.orderBy("items.id", "desc") from "items"
.whereRaw(modequery); ${tag
? 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)}
if(tag) { ${ user
items = items.innerJoin( ? db`and "items".username ilike ${'%' + user + '%'}`
sql("tags") : db``
.select("tags_assign.item_id", "tags.tag") }
.leftJoin("tags_assign", "tags_assign.tag_id", "tags.id") ${ mime
.where("tags.tag", "ilike", "%"+tag+"%") ? db`and "items".mime ilike ${mime + '/%'}`
.groupBy("tags.tag", "tags_assign.item_id") : db``
.as("st"), }
"st.item_id", "items.id" ${ tag
) ? db`group by st.item_id, "items".id, "tags_assign".tag_id`
.groupBy('st.tag', 'st.item_id', 'items.id'); : db`group by "items".id`
}
order by "items".id desc
`;
} }
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;
@ -228,11 +279,13 @@ 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 sql('favorites') const favorites = await db`
.select('user.user', 'user_options.avatar') select "user".user, "user_options".avatar
.leftJoin('user', 'user.id', 'favorites.user_id') from "favorites"
.leftJoin('user_options', 'user_options.user_id', 'favorites.user_id') left join "user" on "user".id = "favorites".user_id
.where('favorites.item_id', itemid); left join "user_options" on "user_options".user_id = "favorites".user_id
where "favorites".item_id = ${itemid}
`;
let coverart = true; let coverart = true;
try { try {
@ -286,44 +339,65 @@ 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) { if(o.fav) { // dood lol
item = sql("favorites") item = db`
.select('items.*') select "items".*
.leftJoin('items', 'items.id', 'favorites.item_id') from "favorites"
.leftJoin('user', 'user.id', 'favorites.user_id') left join "items" on "items".id = "favorites".item_id
.whereRaw(modequery) left join "user" on "user".id = "favorites".user_id
.orderByRaw("random()") ${ 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``
}
order by random()
limit 1
`;
} }
else { else {
item = sql("items") item = db`
.select("*") select *
.orderByRaw("random()") from "items"
.whereRaw(modequery); ${ tag
? 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)}
if(tag) { ${ user
item = item.innerJoin( ? db`and "items".username ilike ${'%' + user + '%'}`
sql("tags") : db``
.select("tags_assign.item_id", "tags.tag") }
.leftJoin("tags_assign", "tags_assign.tag_id", "tags.id") ${ mime
.where("tags.tag", "ilike", "%"+tag+"%") ? db`and "items".mime ilike ${mime + '/%'}`
.groupBy("tags_assign.item_id", "tags.tag") : db``
.as("st"), }
"st.item_id", "items.id" order by random()
) limit 1
.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;

View File

@ -1,4 +1,4 @@
import sql from "../sql.mjs"; import db 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,20 +24,26 @@ export default (router, tpl) => {
}); });
router.post(/^\/login(\/)?$/, async (req, res) => { router.post(/^\/login(\/)?$/, async (req, res) => {
const user = await sql("user").where("login", req.post.username.toLowerCase()).limit(1); const user = await db`
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 sql("user_sessions") // delete unused sessions await db`
.where('last_action', '<=', (Date.now() - 6048e5)) delete from user_sessions
.andWhere('kmsi', 0) where last_action <= ${(Date.now() - 6048e5)}
.del(); and kmsi = 0
`;
const session = lib.md5(lib.createID()); const session = lib.md5(lib.createID());
await sql("user_sessions").insert({ const blah = {
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"],
@ -45,7 +51,13 @@ 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",
@ -55,11 +67,18 @@ export default (router, tpl) => {
}); });
router.get(/^\/logout$/, auth, async (req, res) => { router.get(/^\/logout$/, auth, async (req, res) => {
const usersession = await sql("user_sessions").where("id", req.session.sess_id); const usersession = await db`
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 sql("user_sessions").where("id", req.session.sess_id).del(); await db`
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",
@ -86,10 +105,12 @@ export default (router, tpl) => {
}); });
router.get(/^\/admin\/sessions(\/)?$/, auth, async (req, res) => { router.get(/^\/admin\/sessions(\/)?$/, auth, async (req, res) => {
const rows = await sql("user_sessions") const rows = await db`
.leftJoin("user", "user.id", "user_sessions.user_id") select "user_sessions".*, "user".user
.select("user_sessions.*", "user.user") from "user_sessions"
.orderBy("user_sessions.last_used", "desc"); left join "user" on "user".id = "user_sessions".user_id
order by "user_sessions".last_used desc
`;
res.reply({ res.reply({
body: tpl.render("admin/sessions", { body: tpl.render("admin/sessions", {
@ -108,17 +129,22 @@ export default (router, tpl) => {
if(tag.startsWith('src:')) { if(tag.startsWith('src:')) {
tag = tag.substring(4); tag = tag.substring(4);
ret = await sql('items') ret = await db`
.where('src', 'ilike', '%'+tag+'%') select *
.limit(500); from "items"
where src ilike ${'%' + tag + '%'}
limit 500
`;
} }
else { else {
rows = await sql("tags") rows = await db`
.select("items.id", "items.username", "tags.tag") select "items".id, "items".username, "tags".tag
.leftJoin("tags_assign", "tags_assign.tag_id", "tags.id") from "tags"
.leftJoin("items", "items.id", "tags_assign.item_id") left join "tags_assign" on "tags_assign".tag_id = "tags".id
.where("tags.tag", "like", '%'+tag+'%') left join "items" on "items".id = "tags_assign".item_id
.limit(500); where "tags".tag ilike ${'%' + tag + '%'}
limit 500
`;
ret = search(rows, tag); ret = search(rows, tag);
} }
} }

View File

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

View File

@ -1,4 +1,4 @@
import sql from '../../sql.mjs'; import db 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 = ( const itemid = (await db`
await sql('items') select id
.select('id') from "items"
.where('id', avatar) where id = ${+avatar}
)?.[0]?.id; `)?.[0]?.id;
if(!itemid) { if(!itemid) {
return res.json({ return res.json({
@ -25,11 +25,14 @@ export default router => {
}, 404); // not found }, 404); // not found
} }
const q = await sql('user_options') const q = await db`
.update({ update "user_options" set ${
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 sql from '../../sql.mjs'; import db from '../../sql.mjs';
import lib from '../../lib.mjs'; import lib from '../../lib.mjs';
export default router => { export default router => {
@ -38,22 +38,32 @@ export default router => {
} }
try { try {
let tagid = ( let tagid = (await db`
await sql("tags") select id
.select("id") from "tags"
.whereRaw("normalized = slugify(?)", [ tagname ]) where normalized = slugify(${tagname})
)?.[0]?.id; `)?.[0]?.id;
if(!tagid) { // create new tag if(!tagid) { // create new tag
tagid = (await sql("tags").returning("id").insert({ tagid = (await db`
insert into "tags" ${
db({
tag: tagname tag: tagname
}))[0]; })
} }
await sql("tags_assign").insert({ returning id
tag_id: tagid, `)[0].id;
item_id: postid, }
user_id: req.session.id
}); await db`
insert into "tags_assign" ${
db({
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,
@ -83,20 +93,24 @@ 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 sql('tags_assign').insert({ await db`
item_id: postid, insert into "tags_assign" ${
db({
item_id: +postid,
tag_id: 1, tag_id: 1,
user_id: req.session.id user_id: +req.session.id
}); })
}
`;
} }
else { else {
// update // update
await sql('tags_assign') await db`
.update({ update "tags_assign"
tag_id: sql.raw('(array[2,1])[tag_id]') set tag_id = (array[2,1])[tag_id]
}) where tag_id = any(array[1,2])
.whereRaw('tag_id = any(array[1,2])') and item_id = ${+postid}
.andWhere('item_id', postid); `;
} }
return res.json({ return res.json({
@ -129,10 +143,16 @@ export default router => {
}); });
} }
let q = sql("tags_assign").where("tag_id", tagid).andWhere("item_id", postid).del(); let q = await db`
if(req.session.level < 50) delete from "tags_assign"
q = q.andWhere("user_id", req.session.id); where tag_id = ${+tagid}
const reply = !!(await q); and item_id = ${+postid}
${ 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 sql from "../sql.mjs"; import db 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,37 +49,52 @@ export default (router, tpl) => {
referer = referertmp.split("/").slice(3).join("/"); referer = referertmp.split("/").slice(3).join("/");
if(cfg.allowedModes[mode]) { if(cfg.allowedModes[mode]) {
await sql("user_options") const blah = {
.insert({
user_id: req.session.id, user_id: req.session.id,
mode: mode, mode: mode,
theme: req.theme ?? "f0ck" theme: req.theme ?? "f0ck"
}) };
.onConflict("user_id")
.merge(); await db`
insert into "user_options" ${
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 sql('tags_assign') const list = await db`
.select('user.user', sql.raw('coalesce(user_options.avatar, 47319) as avatar')) select
.leftJoin('user', 'user.id', 'tags_assign.user_id') "user".user,
.leftJoin('user_options', 'user_options.user_id', 'user.id') coalesce("user_options".avatar, 47319) as avatar,
.groupBy('user.user', 'user_options.avatar') count(distinct(tag_id, item_id)) as count
.orderBy('count', 'desc') from "tags_assign"
.countDistinct('tag_id', 'item_id', { as: 'count' }); left join "user" on "user".id = "tags_assign".user_id
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 sql.with('t', sql.raw("select split_part(substring(src, position('//' in src)+2), '/', 1) part from items")) const hoster = await db`
.from('t') with t as (
.select('t.part') select
.count('t.part as c') split_part(substring(src, position('//' in src)+2), '/', 1) part
.groupBy('t.part') from items
.orderBy('c', 'desc') )
.limit(20); select t.part, count(t.part) as c
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 sql from "../../inc/sql.mjs"; import db from "../../inc/sql.mjs";
const auth = async (req, res, next) => { const auth = async (req, res, next) => {
if(!req.session) if(!req.session)
@ -9,9 +9,16 @@ 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,7 +1,11 @@
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: 'pgnative', client: 'pg',
connection: cfg.sql connection: cfg.sql
}); });*/
//export const db = postgres(cfg.sql);
export default postgres(cfg.sql);

View File

@ -1,7 +1,5 @@
import { getLevel } from "../admin.mjs"; import { getLevel } from "../admin.mjs";
import fetch from "flumm-fetch-cookies"; import fetch from "flumm-fetch";
import sql from "../sql.mjs";
import vm from "vm"; import vm from "vm";
let maxoutput = 750; let maxoutput = 750;
@ -9,7 +7,6 @@ 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 sql from "../sql.mjs"; import db from "../sql.mjs";
export default async bot => { export default async bot => {
@ -14,14 +14,22 @@ export default async bot => {
if(id <= 0) if(id <= 0)
return false; return false;
const f0ck = await sql("items").select("dest").where("id", id).limit(1); const f0ck = await db`
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 sql("items").where("id", id).del().limit(1); await db`
delete from "items"
where id = ${+id}
`;
return id; return id;
}))).filter(d => d); }))).filter(d => d);

View File

@ -1,14 +1,17 @@
import fetch from "flumm-fetch-cookies"; import fetch from "flumm-fetch";
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 sql from "../sql.mjs"; import db from "../sql.mjs";
import lib from "../lib.mjs"; import lib from "../lib.mjs";
const cleanTags = async () => { /*const cleanTags = async () => {
const tags = await sql("tags") const tags = await db`
.leftJoin("tags_assign", "tags_assign.tag_id", "tags.id") select *
.whereNull("tags_assign.item_id"); from "tags"
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;
@ -23,7 +26,7 @@ const cleanTags = async () => {
}); });
await deleteTag.del(); await deleteTag.del();
return dtags; return dtags;
}; };*/
export default async bot => { export default async bot => {
@ -49,7 +52,10 @@ 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 sql("items").select("id"); const rows = await db`
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)
@ -69,10 +75,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 sql from "../sql.mjs"; import db 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,14 +12,15 @@ 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();
let query = sql("items").select("id", "mime", "size", "username", "userchannel", "usernetwork", "stamp"); const rows = await db`
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 sql from "../sql.mjs"; import db 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: true, active: false,
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 sql from "../sql.mjs"; import db 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-cookies"; import fetch from "flumm-fetch";
import fs from "fs"; import fs from "fs";
import { exec as _exec } from "child_process"; import { exec as _exec } from "child_process";
@ -45,12 +45,18 @@ export default async bot => {
links.forEach(async link => { links.forEach(async link => {
// check repost (link) // check repost (link)
const q_repost = await sql("items").select("id").where("src", link); const q_repost = await db`
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 sql.select(sql.raw("gen_random_uuid() as uuid")))[0].uuid.substring(0, 8); const uuid = (await db`
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;
@ -108,14 +114,20 @@ export default async bot => {
} }
// check repost (checksum) // check repost (checksum)
const q_repostc = await sql("items").select("id").where("checksum", checksum); const q_repostc = await db`
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 sql("items").insert({ await db`
insert into items ${
db({
src: e.photo ? "" : link, src: e.photo ? "" : link,
dest: filename, dest: filename,
mime: mime, mime: mime,
@ -126,8 +138,16 @@ export default async bot => {
usernetwork: e.network, usernetwork: e.network,
stamp: ~~(new Date() / 1000), stamp: ~~(new Date() / 1000),
active: 1 active: 1
}); }, 'src', 'dest', 'mime', 'size', 'checksum', 'username', 'userchannel', 'usernetwork', 'stamp', 'active')
const itemid = (await sql('items').where('dest', filename).limit(1))[0].id; }
`;
const itemid = (await db`
select *
from "items"
where dest = ${filename}
limit 1
`)[0].id;
// generate thumbnail // generate thumbnail
try { try {
@ -184,11 +204,15 @@ export default async bot => {
} }
if(tag === 'sfw' || tag === 'nsfw') { if(tag === 'sfw' || tag === 'nsfw') {
await sql("tags_assign").insert({ await db`
insert into "tags_assign" ${
db({
tag_id: tag === "sfw" ? 1 : 2, tag_id: tag === "sfw" ? 1 : 2,
item_id: itemid, item_id: itemid,
user_id: 7 // user: autotagger (ID: 7) 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,12 +1,8 @@
import sql from "../sql.mjs"; import db 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",
@ -17,7 +13,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 getTags(id)).map(t => t.tag); const tags = (await lib.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(', ')}`);
@ -32,7 +28,7 @@ export default async bot => {
if(!id) if(!id)
return e.reply("lol no"); return e.reply("lol no");
const tags = (await getTags(id)).map(t => t.tag); const tags = (await lib.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(",")
@ -44,26 +40,38 @@ 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 sql("tags").select("id", "tag").where("tag", ntag); const tag_exists = await db`
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 sql("tags").insert({ tagid = (await db`
insert into "tags" ${
db({
tag: ntag tag: ntag
}))[0]; }, 'tag')
}
`)[0];
} }
else { else {
tagid = tag_exists[0].id; tagid = tag_exists[0].id;
} }
return await sql("tags_assign").insert({ return await db`
insert into "tags_assign" ${
db({
tag_id: tagid, tag_id: tagid,
item_id: id, item_id: id,
prefix: `${e.user.prefix}${e.channel}` prefix: `${e.user.prefix}${e.channel}`
}); }, 'tag_id', 'item_id', 'prefix')
}
`;
} catch(err) { } catch(err) {
console.error(err); console.error(err);
} }
})); }));
const ntags = (await getTags(id)).map(t => t.tag); const ntags = (await lib.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(', ')}`);
@ -78,7 +86,7 @@ export default async bot => {
if(!id) if(!id)
return e.reply("lol no"); return e.reply("lol no");
const tags = await getTags(id); const tags = await lib.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(",")
@ -97,12 +105,18 @@ export default async bot => {
}; };
} }
let q = sql("tags_assign").where("tag_id", tagid).andWhere("item_id", id).del(); const q = await db`
if(getLevel(e.user).level < 50) delete from "tags_assign"
q = q.andWhere("prefix", `${e.user.prefix}${e.channel}`); where tag_id = ${+tagid}
and item_id = ${+id}
${ getLevel(e.user.level < 50)
? db`and prefix = ${e.user.prefix + e.channel}`
: db``
}
`;
return { return {
success: !!(await q), success: !!q,
tag: rtag, tag: rtag,
tagid: tagid tagid: tagid
}; };
@ -110,7 +124,7 @@ export default async bot => {
e.reply(JSON.stringify(res)); e.reply(JSON.stringify(res));
const ntags = (await getTags(id)).map(t => t.tag); const ntags = (await lib.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 sql from "./inc/sql.mjs"; import db 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,12 +64,14 @@ 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 sql("user_sessions") // get user const user = await db`
.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".*
.where("user_sessions.session", lib.md5(req.cookies.session)) from "user_sessions"
.leftJoin("user", "user.id", "user_sessions.user_id") left join "user" on "user".id = "user_sessions".user_id
.leftJoin("user_options", "user_options.user_id", "user_sessions.user_id") left join "user_options" on "user_options".user_id = "user_sessions".user_id
.limit(1); where "user_sessions".session = ${lib.md5(req.cookies.session)}
limit 1
`;
if(user.length === 0) { if(user.length === 0) {
return res.writeHead(307, { // delete session return res.writeHead(307, { // delete session
@ -80,21 +82,33 @@ import flummpress from "flummpress";
} }
req.session = user[0]; req.session = user[0];
await sql("user_sessions") // log last action
.update("last_used", ~~(Date.now() / 1e3)) // log last action
.update("last_action", req.url.pathname) await db`
.update("browser", req.headers["user-agent"]) update "user_sessions" set ${
.where("id", user[0].sess_id); db({
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 sql("user_options") await db`
.insert({ insert into "user_options" ${
user_id: user[0].id, db({
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
`;
} }
}); });