Merge pull request #370 from mchangrh/switch-axios

replace node-fetch with axios in src
This commit is contained in:
Ajay Ramachandran
2021-09-27 20:24:34 -04:00
committed by GitHub
8 changed files with 105 additions and 290 deletions

184
package-lock.json generated
View File

@@ -16,7 +16,6 @@
"express": "^4.17.1", "express": "^4.17.1",
"express-promise-router": "^4.1.0", "express-promise-router": "^4.1.0",
"express-rate-limit": "^5.3.0", "express-rate-limit": "^5.3.0",
"node-fetch": "^2.6.2",
"pg": "^8.7.1", "pg": "^8.7.1",
"redis": "^3.1.2", "redis": "^3.1.2",
"sync-mysql": "^3.0.1" "sync-mysql": "^3.0.1"
@@ -28,10 +27,8 @@
"@types/express-rate-limit": "^5.1.3", "@types/express-rate-limit": "^5.1.3",
"@types/mocha": "^9.0.0", "@types/mocha": "^9.0.0",
"@types/node": "^16.9.4", "@types/node": "^16.9.4",
"@types/node-fetch": "^2.5.12",
"@types/pg": "^8.6.1", "@types/pg": "^8.6.1",
"@types/redis": "^2.8.32", "@types/redis": "^2.8.32",
"@types/request": "^2.48.7",
"@typescript-eslint/eslint-plugin": "^4.31.2", "@typescript-eslint/eslint-plugin": "^4.31.2",
"@typescript-eslint/parser": "^4.31.2", "@typescript-eslint/parser": "^4.31.2",
"eslint": "^7.32.0", "eslint": "^7.32.0",
@@ -399,12 +396,6 @@
"@types/node": "*" "@types/node": "*"
} }
}, },
"node_modules/@types/caseless": {
"version": "0.12.2",
"resolved": "https://registry.npmjs.org/@types/caseless/-/caseless-0.12.2.tgz",
"integrity": "sha512-6ckxMjBBD8URvjB6J3NcnuAn5Pkl7t3TizAg+xdlzzQGSPSmBcXf8KoIH0ua/i+tio+ZRUHEXp0HEmvaR4kt0w==",
"dev": true
},
"node_modules/@types/connect": { "node_modules/@types/connect": {
"version": "3.4.33", "version": "3.4.33",
"resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.33.tgz", "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.33.tgz",
@@ -480,16 +471,6 @@
"integrity": "sha512-KDazLNYAGIuJugdbULwFZULF9qQ13yNWEBFnfVpqlpgAAo6H/qnM9RjBgh0A0kmHf3XxAKLdN5mTIng9iUvVLA==", "integrity": "sha512-KDazLNYAGIuJugdbULwFZULF9qQ13yNWEBFnfVpqlpgAAo6H/qnM9RjBgh0A0kmHf3XxAKLdN5mTIng9iUvVLA==",
"devOptional": true "devOptional": true
}, },
"node_modules/@types/node-fetch": {
"version": "2.5.12",
"resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.5.12.tgz",
"integrity": "sha512-MKgC4dlq4kKNa/mYrwpKfzQMB5X3ee5U6fSprkKpToBqBmX4nFZL9cW5jl6sWn+xpRJ7ypWh2yyqqr8UUCstSw==",
"dev": true,
"dependencies": {
"@types/node": "*",
"form-data": "^3.0.0"
}
},
"node_modules/@types/pg": { "node_modules/@types/pg": {
"version": "8.6.1", "version": "8.6.1",
"resolved": "https://registry.npmjs.org/@types/pg/-/pg-8.6.1.tgz", "resolved": "https://registry.npmjs.org/@types/pg/-/pg-8.6.1.tgz",
@@ -522,32 +503,6 @@
"@types/node": "*" "@types/node": "*"
} }
}, },
"node_modules/@types/request": {
"version": "2.48.7",
"resolved": "https://registry.npmjs.org/@types/request/-/request-2.48.7.tgz",
"integrity": "sha512-GWP9AZW7foLd4YQxyFZDBepl0lPsWLMEXDZUjQ/c1gqVPDPECrRZyEzuhJdnPWioFCq3Tv0qoGpMD6U+ygd4ZA==",
"dev": true,
"dependencies": {
"@types/caseless": "*",
"@types/node": "*",
"@types/tough-cookie": "*",
"form-data": "^2.5.0"
}
},
"node_modules/@types/request/node_modules/form-data": {
"version": "2.5.1",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-2.5.1.tgz",
"integrity": "sha512-m21N3WOmEEURgk6B9GLOE4RuWOFf28Lhh9qGYeNlGq4VDXUlJy2th2slBNU8Gp8EzloYZOibZJ7t5ecIrFSjVA==",
"dev": true,
"dependencies": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.6",
"mime-types": "^2.1.12"
},
"engines": {
"node": ">= 0.12"
}
},
"node_modules/@types/serve-static": { "node_modules/@types/serve-static": {
"version": "1.13.5", "version": "1.13.5",
"resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.13.5.tgz", "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.13.5.tgz",
@@ -558,12 +513,6 @@
"@types/mime": "*" "@types/mime": "*"
} }
}, },
"node_modules/@types/tough-cookie": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-4.0.1.tgz",
"integrity": "sha512-Y0K95ThC3esLEYD6ZuqNek29lNX2EM1qxV8y2FTLUB0ff5wWrk7az+mLrnNFUnaXcgKye22+sFBRXOgpPILZNg==",
"dev": true
},
"node_modules/@typescript-eslint/eslint-plugin": { "node_modules/@typescript-eslint/eslint-plugin": {
"version": "4.31.2", "version": "4.31.2",
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.31.2.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.31.2.tgz",
@@ -1112,12 +1061,6 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=",
"dev": true
},
"node_modules/axios": { "node_modules/axios": {
"version": "0.21.4", "version": "0.21.4",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz", "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz",
@@ -1622,18 +1565,6 @@
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=",
"dev": true "dev": true
}, },
"node_modules/combined-stream": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
"dev": true,
"dependencies": {
"delayed-stream": "~1.0.0"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/concat-map": { "node_modules/concat-map": {
"version": "0.0.1", "version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
@@ -1790,15 +1721,6 @@
"integrity": "sha512-0ISdNousHvZT2EiFlZeZAHBUvSxmKswVCEf8hW7KWgG4a8MVEu/3Vb6uWYozkjylyCxe0JBIiRB1jV45S70WVQ==", "integrity": "sha512-0ISdNousHvZT2EiFlZeZAHBUvSxmKswVCEf8hW7KWgG4a8MVEu/3Vb6uWYozkjylyCxe0JBIiRB1jV45S70WVQ==",
"dev": true "dev": true
}, },
"node_modules/delayed-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=",
"dev": true,
"engines": {
"node": ">=0.4.0"
}
},
"node_modules/delegates": { "node_modules/delegates": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz",
@@ -2606,20 +2528,6 @@
} }
} }
}, },
"node_modules/form-data": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz",
"integrity": "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==",
"dev": true,
"dependencies": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/forwarded": { "node_modules/forwarded": {
"version": "0.1.2", "version": "0.1.2",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz",
@@ -3858,14 +3766,6 @@
"semver": "^5.4.1" "semver": "^5.4.1"
} }
}, },
"node_modules/node-fetch": {
"version": "2.6.2",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.2.tgz",
"integrity": "sha512-aLoxToI6RfZ+0NOjmWAgn9+LEd30YCkJKFSyWacNZdEKTit/ZMcKjGkTRo8uWEsnIb/hfKecNPEbln02PdWbcA==",
"engines": {
"node": "4.x || >=6.0.0"
}
},
"node_modules/nodemon": { "node_modules/nodemon": {
"version": "2.0.12", "version": "2.0.12",
"resolved": "https://registry.npmjs.org/nodemon/-/nodemon-2.0.12.tgz", "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-2.0.12.tgz",
@@ -6139,12 +6039,6 @@
"@types/node": "*" "@types/node": "*"
} }
}, },
"@types/caseless": {
"version": "0.12.2",
"resolved": "https://registry.npmjs.org/@types/caseless/-/caseless-0.12.2.tgz",
"integrity": "sha512-6ckxMjBBD8URvjB6J3NcnuAn5Pkl7t3TizAg+xdlzzQGSPSmBcXf8KoIH0ua/i+tio+ZRUHEXp0HEmvaR4kt0w==",
"dev": true
},
"@types/connect": { "@types/connect": {
"version": "3.4.33", "version": "3.4.33",
"resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.33.tgz", "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.33.tgz",
@@ -6220,16 +6114,6 @@
"integrity": "sha512-KDazLNYAGIuJugdbULwFZULF9qQ13yNWEBFnfVpqlpgAAo6H/qnM9RjBgh0A0kmHf3XxAKLdN5mTIng9iUvVLA==", "integrity": "sha512-KDazLNYAGIuJugdbULwFZULF9qQ13yNWEBFnfVpqlpgAAo6H/qnM9RjBgh0A0kmHf3XxAKLdN5mTIng9iUvVLA==",
"devOptional": true "devOptional": true
}, },
"@types/node-fetch": {
"version": "2.5.12",
"resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.5.12.tgz",
"integrity": "sha512-MKgC4dlq4kKNa/mYrwpKfzQMB5X3ee5U6fSprkKpToBqBmX4nFZL9cW5jl6sWn+xpRJ7ypWh2yyqqr8UUCstSw==",
"dev": true,
"requires": {
"@types/node": "*",
"form-data": "^3.0.0"
}
},
"@types/pg": { "@types/pg": {
"version": "8.6.1", "version": "8.6.1",
"resolved": "https://registry.npmjs.org/@types/pg/-/pg-8.6.1.tgz", "resolved": "https://registry.npmjs.org/@types/pg/-/pg-8.6.1.tgz",
@@ -6262,31 +6146,6 @@
"@types/node": "*" "@types/node": "*"
} }
}, },
"@types/request": {
"version": "2.48.7",
"resolved": "https://registry.npmjs.org/@types/request/-/request-2.48.7.tgz",
"integrity": "sha512-GWP9AZW7foLd4YQxyFZDBepl0lPsWLMEXDZUjQ/c1gqVPDPECrRZyEzuhJdnPWioFCq3Tv0qoGpMD6U+ygd4ZA==",
"dev": true,
"requires": {
"@types/caseless": "*",
"@types/node": "*",
"@types/tough-cookie": "*",
"form-data": "^2.5.0"
},
"dependencies": {
"form-data": {
"version": "2.5.1",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-2.5.1.tgz",
"integrity": "sha512-m21N3WOmEEURgk6B9GLOE4RuWOFf28Lhh9qGYeNlGq4VDXUlJy2th2slBNU8Gp8EzloYZOibZJ7t5ecIrFSjVA==",
"dev": true,
"requires": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.6",
"mime-types": "^2.1.12"
}
}
}
},
"@types/serve-static": { "@types/serve-static": {
"version": "1.13.5", "version": "1.13.5",
"resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.13.5.tgz", "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.13.5.tgz",
@@ -6297,12 +6156,6 @@
"@types/mime": "*" "@types/mime": "*"
} }
}, },
"@types/tough-cookie": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-4.0.1.tgz",
"integrity": "sha512-Y0K95ThC3esLEYD6ZuqNek29lNX2EM1qxV8y2FTLUB0ff5wWrk7az+mLrnNFUnaXcgKye22+sFBRXOgpPILZNg==",
"dev": true
},
"@typescript-eslint/eslint-plugin": { "@typescript-eslint/eslint-plugin": {
"version": "4.31.2", "version": "4.31.2",
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.31.2.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.31.2.tgz",
@@ -6696,12 +6549,6 @@
"integrity": "sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ==", "integrity": "sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ==",
"dev": true "dev": true
}, },
"asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=",
"dev": true
},
"axios": { "axios": {
"version": "0.21.4", "version": "0.21.4",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz", "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz",
@@ -7099,15 +6946,6 @@
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=",
"dev": true "dev": true
}, },
"combined-stream": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
"dev": true,
"requires": {
"delayed-stream": "~1.0.0"
}
},
"concat-map": { "concat-map": {
"version": "0.0.1", "version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
@@ -7239,12 +7077,6 @@
"integrity": "sha512-0ISdNousHvZT2EiFlZeZAHBUvSxmKswVCEf8hW7KWgG4a8MVEu/3Vb6uWYozkjylyCxe0JBIiRB1jV45S70WVQ==", "integrity": "sha512-0ISdNousHvZT2EiFlZeZAHBUvSxmKswVCEf8hW7KWgG4a8MVEu/3Vb6uWYozkjylyCxe0JBIiRB1jV45S70WVQ==",
"dev": true "dev": true
}, },
"delayed-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=",
"dev": true
},
"delegates": { "delegates": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz",
@@ -7842,17 +7674,6 @@
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.4.tgz", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.4.tgz",
"integrity": "sha512-zwGkiSXC1MUJG/qmeIFH2HBJx9u0V46QGUe3YR1fXG8bXQxq7fLj0RjLZQ5nubr9qNJUZrH+xUcwXEoXNpfS+g==" "integrity": "sha512-zwGkiSXC1MUJG/qmeIFH2HBJx9u0V46QGUe3YR1fXG8bXQxq7fLj0RjLZQ5nubr9qNJUZrH+xUcwXEoXNpfS+g=="
}, },
"form-data": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz",
"integrity": "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==",
"dev": true,
"requires": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
}
},
"forwarded": { "forwarded": {
"version": "0.1.2", "version": "0.1.2",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz",
@@ -8802,11 +8623,6 @@
"semver": "^5.4.1" "semver": "^5.4.1"
} }
}, },
"node-fetch": {
"version": "2.6.2",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.2.tgz",
"integrity": "sha512-aLoxToI6RfZ+0NOjmWAgn9+LEd30YCkJKFSyWacNZdEKTit/ZMcKjGkTRo8uWEsnIb/hfKecNPEbln02PdWbcA=="
},
"nodemon": { "nodemon": {
"version": "2.0.12", "version": "2.0.12",
"resolved": "https://registry.npmjs.org/nodemon/-/nodemon-2.0.12.tgz", "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-2.0.12.tgz",

View File

@@ -23,7 +23,6 @@
"express": "^4.17.1", "express": "^4.17.1",
"express-promise-router": "^4.1.0", "express-promise-router": "^4.1.0",
"express-rate-limit": "^5.3.0", "express-rate-limit": "^5.3.0",
"node-fetch": "^2.6.2",
"pg": "^8.7.1", "pg": "^8.7.1",
"redis": "^3.1.2", "redis": "^3.1.2",
"sync-mysql": "^3.0.1" "sync-mysql": "^3.0.1"
@@ -35,10 +34,8 @@
"@types/express-rate-limit": "^5.1.3", "@types/express-rate-limit": "^5.1.3",
"@types/mocha": "^9.0.0", "@types/mocha": "^9.0.0",
"@types/node": "^16.9.4", "@types/node": "^16.9.4",
"@types/node-fetch": "^2.5.12",
"@types/pg": "^8.6.1", "@types/pg": "^8.6.1",
"@types/redis": "^2.8.32", "@types/redis": "^2.8.32",
"@types/request": "^2.48.7",
"@typescript-eslint/eslint-plugin": "^4.31.2", "@typescript-eslint/eslint-plugin": "^4.31.2",
"@typescript-eslint/parser": "^4.31.2", "@typescript-eslint/parser": "^4.31.2",
"eslint": "^7.32.0", "eslint": "^7.32.0",

View File

@@ -1,7 +1,6 @@
import { db } from "../databases/databases"; import { db } from "../databases/databases";
import { config } from "../config"; import { config } from "../config";
import { Request, Response } from "express"; import { Request, Response } from "express";
import fetch from "node-fetch";
import axios from "axios"; import axios from "axios";
import { Logger } from "../utils/logger"; import { Logger } from "../utils/logger";
@@ -55,13 +54,12 @@ function updateExtensionUsers() {
const mozillaAddonsUrl = "https://addons.mozilla.org/api/v3/addons/addon/sponsorblock/"; const mozillaAddonsUrl = "https://addons.mozilla.org/api/v3/addons/addon/sponsorblock/";
const chromeExtensionUrl = "https://chrome.google.com/webstore/detail/sponsorblock-for-youtube/mnjggcdmjocbbbhaepdhchncahnbgone"; const chromeExtensionUrl = "https://chrome.google.com/webstore/detail/sponsorblock-for-youtube/mnjggcdmjocbbbhaepdhchncahnbgone";
fetch(mozillaAddonsUrl) axios.get(mozillaAddonsUrl)
.then(res => res.json() as Record<string, any>) .then(res => {
.then(data => { firefoxUsersCache = res.data.average_daily_users;
firefoxUsersCache = data.average_daily_users; axios.get(chromeExtensionUrl)
fetch(chromeExtensionUrl) .then(res => {
.then(res => res.text()) const body = res.data;
.then(body => {
// 2021-01-05 // 2021-01-05
// [...]<span><meta itemprop="interactionCount" content="UserDownloads:100.000+"/><meta itemprop="opera[...] // [...]<span><meta itemprop="interactionCount" content="UserDownloads:100.000+"/><meta itemprop="opera[...]
const matchingString = '"UserDownloads:'; const matchingString = '"UserDownloads:';

View File

@@ -3,7 +3,6 @@ import { Logger } from "../utils/logger";
import { db, privateDB } from "../databases/databases"; import { db, privateDB } from "../databases/databases";
import { getMaxResThumbnail, YouTubeAPI } from "../utils/youtubeApi"; import { getMaxResThumbnail, YouTubeAPI } from "../utils/youtubeApi";
import { getSubmissionUUID } from "../utils/getSubmissionUUID"; import { getSubmissionUUID } from "../utils/getSubmissionUUID";
import fetch from "node-fetch";
import { getHash } from "../utils/getHash"; import { getHash } from "../utils/getHash";
import { getIP } from "../utils/getIP"; import { getIP } from "../utils/getIP";
import { getFormattedTime } from "../utils/getFormattedTime"; import { getFormattedTime } from "../utils/getFormattedTime";
@@ -20,6 +19,7 @@ import { UserID } from "../types/user.model";
import { isUserVIP } from "../utils/isUserVIP"; import { isUserVIP } from "../utils/isUserVIP";
import { parseUserAgent } from "../utils/userAgent"; import { parseUserAgent } from "../utils/userAgent";
import { getService } from "../utils/getService"; import { getService } from "../utils/getService";
import axios from "axios";
type CheckResult = { type CheckResult = {
pass: boolean, pass: boolean,
@@ -80,28 +80,22 @@ async function sendWebhooks(apiVideoInfo: APIVideoInfo, userID: string, videoID:
// Then send a notification to discord // Then send a notification to discord
if (config.discordFirstTimeSubmissionsWebhookURL === null || userSubmissionCountRow.submissionCount > 1) return; if (config.discordFirstTimeSubmissionsWebhookURL === null || userSubmissionCountRow.submissionCount > 1) return;
fetch(config.discordFirstTimeSubmissionsWebhookURL, { axios.post(config.discordFirstTimeSubmissionsWebhookURL, {
method: "POST", "embeds": [{
body: JSON.stringify({ "title": data?.title,
"embeds": [{ "url": `https://www.youtube.com/watch?v=${videoID}&t=${(parseInt(startTime.toFixed(0)) - 2)}`,
"title": data?.title, "description": `Submission ID: ${UUID}\
"url": `https://www.youtube.com/watch?v=${videoID}&t=${(parseInt(startTime.toFixed(0)) - 2)}`, \n\nTimestamp: \
"description": `Submission ID: ${UUID}\ ${getFormattedTime(startTime)} to ${getFormattedTime(endTime)}\
\n\nTimestamp: \ \n\nCategory: ${segmentInfo.category}`,
${getFormattedTime(startTime)} to ${getFormattedTime(endTime)}\ "color": 10813440,
\n\nCategory: ${segmentInfo.category}`, "author": {
"color": 10813440, "name": userID,
"author": { },
"name": userID, "thumbnail": {
}, "url": getMaxResThumbnail(data) || "",
"thumbnail": { },
"url": getMaxResThumbnail(data) || "", }],
},
}],
}),
headers: {
"Content-Type": "application/json"
}
}) })
.then(res => { .then(res => {
if (res.status >= 400) { if (res.status >= 400) {
@@ -136,28 +130,22 @@ async function sendWebhooksNB(userID: string, videoID: string, UUID: string, sta
// Send discord message // Send discord message
if (config.discordNeuralBlockRejectWebhookURL === null) return; if (config.discordNeuralBlockRejectWebhookURL === null) return;
fetch(config.discordNeuralBlockRejectWebhookURL, { axios.post(config.discordNeuralBlockRejectWebhookURL, {
method: "POST", "embeds": [{
body: JSON.stringify({ "title": ytData.items[0].snippet.title,
"embeds": [{ "url": `https://www.youtube.com/watch?v=${videoID}&t=${(parseFloat(startTime.toFixed(0)) - 2)}`,
"title": ytData.items[0].snippet.title, "description": `**Submission ID:** ${UUID}\
"url": `https://www.youtube.com/watch?v=${videoID}&t=${(parseFloat(startTime.toFixed(0)) - 2)}`, \n**Timestamp:** ${getFormattedTime(startTime)} to ${getFormattedTime(endTime)}\
"description": `**Submission ID:** ${UUID}\ \n**Predicted Probability:** ${probability}\
\n**Timestamp:** ${getFormattedTime(startTime)} to ${getFormattedTime(endTime)}\ \n**Category:** ${category}\
\n**Predicted Probability:** ${probability}\ \n**Submitted by:** ${submittedBy}\
\n**Category:** ${category}\ \n**Total User Submissions:** ${submissionInfoRow.count}\
\n**Submitted by:** ${submittedBy}\ \n**Ignored User Submissions:** ${submissionInfoRow.disregarded}`,
\n**Total User Submissions:** ${submissionInfoRow.count}\ "color": 10813440,
\n**Ignored User Submissions:** ${submissionInfoRow.disregarded}`, "thumbnail": {
"color": 10813440, "url": ytData.items[0].snippet.thumbnails.maxres ? ytData.items[0].snippet.thumbnails.maxres.url : "",
"thumbnail": { },
"url": ytData.items[0].snippet.thumbnails.maxres ? ytData.items[0].snippet.thumbnails.maxres.url : "", }]
},
}],
}),
headers: {
"Content-Type": "application/json"
}
}) })
.then(res => { .then(res => {
if (res.status >= 400) { if (res.status >= 400) {
@@ -236,11 +224,11 @@ async function autoModerateSubmission(apiVideoInfo: APIVideoInfo,
// Check NeuralBlock // Check NeuralBlock
const neuralBlockURL = config.neuralBlockURL; const neuralBlockURL = config.neuralBlockURL;
if (!neuralBlockURL) return false; if (!neuralBlockURL) return false;
const response = await fetch(`${neuralBlockURL}/api/checkSponsorSegments?vid=${submission.videoID} const response = await axios.get(`${neuralBlockURL}/api/checkSponsorSegments?vid=${submission.videoID}
&segments=${nbString.substring(0, nbString.length - 1)}`); &segments=${nbString.substring(0, nbString.length - 1)}`, { validateStatus: () => true });
if (!response.ok) return false; if (response.status !== 200) return false;
const nbPredictions = await response.json() as Record<string, any>; const nbPredictions = response.data;
let nbDecision = false; let nbDecision = false;
let predictionIdx = 0; //Keep track because only sponsor categories were submitted let predictionIdx = 0; //Keep track because only sponsor categories were submitted
for (let i = 0; i < segments.length; i++) { for (let i = 0; i < segments.length; i++) {
@@ -531,12 +519,9 @@ async function checkRateLimit(userID:string, videoID: VideoID, timeSubmitted: nu
} }
function proxySubmission(req: Request) { function proxySubmission(req: Request) {
fetch(`${config.proxySubmission}/api/skipSegments?userID=${req.query.userID}&videoID=${req.query.videoID}`, { axios.post(`${config.proxySubmission}/api/skipSegments?userID=${req.query.userID}&videoID=${req.query.videoID}`, req.body)
method: "POST", .then(res => {
body: req.body, Logger.debug(`Proxy Submission: ${res.status} (${res.data})`);
})
.then(async res => {
Logger.debug(`Proxy Submission: ${res.status} (${(await res.text())})`);
}) })
.catch(() => { .catch(() => {
Logger.error("Proxy Submission: Failed to make call"); Logger.error("Proxy Submission: Failed to make call");

View File

@@ -1,7 +1,6 @@
import { Request, Response } from "express"; import { Request, Response } from "express";
import { Logger } from "../utils/logger"; import { Logger } from "../utils/logger";
import { isUserVIP } from "../utils/isUserVIP"; import { isUserVIP } from "../utils/isUserVIP";
import fetch from "node-fetch";
import { getMaxResThumbnail, YouTubeAPI } from "../utils/youtubeApi"; import { getMaxResThumbnail, YouTubeAPI } from "../utils/youtubeApi";
import { db, privateDB } from "../databases/databases"; import { db, privateDB } from "../databases/databases";
import { dispatchEvent, getVoteAuthor, getVoteAuthorRaw } from "../utils/webhookUtils"; import { dispatchEvent, getVoteAuthor, getVoteAuthorRaw } from "../utils/webhookUtils";
@@ -13,6 +12,7 @@ import { UserID } from "../types/user.model";
import { Category, CategoryActionType, HashedIP, IPAddress, SegmentUUID, Service, VideoID, VideoIDHash, Visibility } from "../types/segments.model"; import { Category, CategoryActionType, HashedIP, IPAddress, SegmentUUID, Service, VideoID, VideoIDHash, Visibility } from "../types/segments.model";
import { getCategoryActionType } from "../utils/categoryInfo"; import { getCategoryActionType } from "../utils/categoryInfo";
import { QueryCacher } from "../utils/queryCacher"; import { QueryCacher } from "../utils/queryCacher";
import axios from "axios";
const voteTypes = { const voteTypes = {
normal: 0, normal: 0,
@@ -111,40 +111,34 @@ async function sendWebhooks(voteData: VoteData) {
// Send discord message // Send discord message
if (webhookURL !== null && !isUpvote) { if (webhookURL !== null && !isUpvote) {
fetch(webhookURL, { axios.post(webhookURL, {
method: "POST", "embeds": [{
body: JSON.stringify({ "title": data?.title,
"embeds": [{ "url": `https://www.youtube.com/watch?v=${submissionInfoRow.videoID}&t=${(submissionInfoRow.startTime.toFixed(0) - 2)}`,
"title": data?.title, "description": `**${voteData.row.votes} Votes Prior | \
"url": `https://www.youtube.com/watch?v=${submissionInfoRow.videoID}&t=${(submissionInfoRow.startTime.toFixed(0) - 2)}`, ${(voteData.row.votes + voteData.incrementAmount - voteData.oldIncrementAmount)} Votes Now | ${voteData.row.views} \
"description": `**${voteData.row.votes} Votes Prior | \ Views**\n\n**Submission ID:** ${voteData.UUID}\
${(voteData.row.votes + voteData.incrementAmount - voteData.oldIncrementAmount)} Votes Now | ${voteData.row.views} \ \n**Category:** ${submissionInfoRow.category}\
Views**\n\n**Submission ID:** ${voteData.UUID}\ \n\n**Submitted by:** ${submissionInfoRow.userName}\n${submissionInfoRow.userID}\
\n**Category:** ${submissionInfoRow.category}\ \n\n**Total User Submissions:** ${submissionInfoRow.count}\
\n\n**Submitted by:** ${submissionInfoRow.userName}\n${submissionInfoRow.userID}\ \n**Ignored User Submissions:** ${submissionInfoRow.disregarded}\
\n\n**Total User Submissions:** ${submissionInfoRow.count}\ \n\n**Timestamp:** \
\n**Ignored User Submissions:** ${submissionInfoRow.disregarded}\ ${getFormattedTime(submissionInfoRow.startTime)} to ${getFormattedTime(submissionInfoRow.endTime)}`,
\n\n**Timestamp:** \ "color": 10813440,
${getFormattedTime(submissionInfoRow.startTime)} to ${getFormattedTime(submissionInfoRow.endTime)}`, "author": {
"color": 10813440, "name": voteData.finalResponse?.webhookMessage ??
"author": { voteData.finalResponse?.finalMessage ??
"name": voteData.finalResponse?.webhookMessage ?? getVoteAuthor(userSubmissionCountRow.submissionCount, voteData.isVIP, voteData.isOwnSubmission),
voteData.finalResponse?.finalMessage ?? },
getVoteAuthor(userSubmissionCountRow.submissionCount, voteData.isVIP, voteData.isOwnSubmission), "thumbnail": {
}, "url": getMaxResThumbnail(data) || "",
"thumbnail": { },
"url": getMaxResThumbnail(data) || "", }],
},
}],
}),
headers: {
"Content-Type": "application/json"
}
}) })
.then(async res => { .then(res => {
if (res.status >= 400) { if (res.status >= 400) {
Logger.error("Error sending reported submission Discord hook"); Logger.error("Error sending reported submission Discord hook");
Logger.error(JSON.stringify((await res.text()))); Logger.error(JSON.stringify((res.data)));
Logger.error("\n"); Logger.error("\n");
} }
}) })

View File

@@ -1,6 +1,6 @@
import { config } from "../config"; import { config } from "../config";
import { Logger } from "../utils/logger"; import { Logger } from "../utils/logger";
import fetch from "node-fetch"; import axios from "axios";
function getVoteAuthorRaw(submissionCount: number, isVIP: boolean, isOwnSubmission: boolean): string { function getVoteAuthorRaw(submissionCount: number, isVIP: boolean, isOwnSubmission: boolean): string {
if (isOwnSubmission) { if (isOwnSubmission) {
@@ -37,9 +37,10 @@ function dispatchEvent(scope: string, data: Record<string, unknown>): void {
const scopes = webhook.scopes || []; const scopes = webhook.scopes || [];
if (!scopes.includes(scope.toLowerCase())) return; if (!scopes.includes(scope.toLowerCase())) return;
fetch(webhookURL, { axios.request({
url: webhookURL,
method: "POST", method: "POST",
body: JSON.stringify(data), data,
headers: { headers: {
"Authorization": authKey, "Authorization": authKey,
"Event-Type": scope, // Maybe change this in the future? "Event-Type": scope, // Maybe change this in the future?

View File

@@ -1,8 +1,8 @@
import fetch from "node-fetch";
import { config } from "../config"; import { config } from "../config";
import { Logger } from "./logger"; import { Logger } from "./logger";
import { APIVideoData, APIVideoInfo } from "../types/youtubeApi.model"; import { APIVideoData, APIVideoInfo } from "../types/youtubeApi.model";
import DiskCache from "./diskCache"; import DiskCache from "./diskCache";
import axios from "axios";
export class YouTubeAPI { export class YouTubeAPI {
static async listVideos(videoID: string, ignoreCache = false): Promise<APIVideoInfo> { static async listVideos(videoID: string, ignoreCache = false): Promise<APIVideoInfo> {
@@ -27,11 +27,11 @@ export class YouTubeAPI {
if (!config.newLeafURLs || config.newLeafURLs.length <= 0) return { err: "NewLeaf URL not found", data: null }; if (!config.newLeafURLs || config.newLeafURLs.length <= 0) return { err: "NewLeaf URL not found", data: null };
try { try {
const result = await fetch(`${config.newLeafURLs[Math.floor(Math.random() * config.newLeafURLs.length)]}/api/v1/videos/${videoID}`, { method: "GET" }); const result = await axios.get(`${config.newLeafURLs[Math.floor(Math.random() * config.newLeafURLs.length)]}/api/v1/videos/${videoID}`);
if (result.ok) { if (result.status === 200) {
const data = await result.json() as (Record<string, any>); const data = result.data;
if (data.error as Record<string, string>) { if (data.error) {
Logger.warn(`NewLeaf API Error for ${videoID}: ${data.error}`); Logger.warn(`NewLeaf API Error for ${videoID}: ${data.error}`);
return { err: data.error, data: null }; return { err: data.error, data: null };
} }

24
test/cases/userCounter.ts Normal file
View File

@@ -0,0 +1,24 @@
import axios from "axios";
import assert from "assert";
import { config } from "../../src/config";
import { getHash } from "../../src/utils/getHash";
describe("userCounter", () => {
it("Should return 200", (done) => {
if (!config.userCounterURL) return done(); // skip if no userCounterURL is set
axios.request({
method: "POST",
baseURL: config.userCounterURL,
url: "/api/v1/addIP",
params: {
hashedIP: getHash("127.0.0.1",1)
}
})
.then(res => {
assert.strictEqual(res.status, 200);
done();
})
.catch(err => done(err));
});
});