aboutsummaryrefslogtreecommitdiff
path: root/backup
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2023-03-18 01:49:50 +0300
committerGravatar Vitaly Takmazov2023-06-14 06:16:56 +0300
commit4fe675b24dfdcb8eba2b8d03f573faaaa50b3bdb (patch)
tree28e58d5bae44cd95fec79faed6c582f273608729 /backup
parentbaae026df3007e5892541acb3f555c5a79c24500 (diff)
[backup] 2023 update: modernize code
* Yarn -> NPM * node:url -> WHATWG URL API * lodash/each -> Array.forEach * node-fetch -> Node 18 Fetch API
Diffstat (limited to 'backup')
-rw-r--r--backup/index.js15
-rw-r--r--backup/package-lock.json49
-rw-r--r--backup/package.json10
-rw-r--r--backup/yarn.lock52
4 files changed, 62 insertions, 64 deletions
diff --git a/backup/index.js b/backup/index.js
index 049c5bb9..fccc4439 100644
--- a/backup/index.js
+++ b/backup/index.js
@@ -1,26 +1,23 @@
var argv = require('minimist')(process.argv.slice(2));
-var fetch = require('node-fetch');
-var _ = require('lodash');
-var url = require('url');
if (typeof argv.u !== "string") {
console.log("username must be specified (-u ugnich)");
- return;
+ process.exit(1);
}
var messages = [];
function getBlogData(blogUrl, callback) {
- fetch(url.format(blogUrl))
+ fetch(blogUrl)
.then(function(res) {
return res.json()
})
.then(function(msgs) {
- _.each(msgs, function(message) {
+ msgs.forEach(function(message) {
messages.push(message);
});
if (msgs.length == 20) {
- blog.query.before_mid = msgs.slice(-1).pop().mid;
+ blog.searchParams.set("before_mid", msgs.slice(-1).pop().mid);
setTimeout(getBlogData, 1000, blog, callback);
} else {
callback();
@@ -28,8 +25,8 @@ function getBlogData(blogUrl, callback) {
});
};
-var blog = url.parse("https://api.juick.com/messages", true);
-blog.query.uname = argv.u;
+var blog = new URL("https://api.juick.com/messages");
+blog.searchParams.append("uname", argv.u);
getBlogData(blog, function() {
console.log(JSON.stringify(messages));
diff --git a/backup/package-lock.json b/backup/package-lock.json
new file mode 100644
index 00000000..cf249751
--- /dev/null
+++ b/backup/package-lock.json
@@ -0,0 +1,49 @@
+{
+ "name": "juick-backup",
+ "version": "1.0.0",
+ "lockfileVersion": 2,
+ "requires": true,
+ "packages": {
+ "": {
+ "name": "juick-backup",
+ "version": "1.0.0",
+ "license": "MIT",
+ "dependencies": {
+ "minimist": "^1.2.8"
+ },
+ "devDependencies": {
+ "@types/node": "^18.15.3"
+ },
+ "engines": {
+ "node": ">= 18"
+ }
+ },
+ "node_modules/@types/node": {
+ "version": "18.15.3",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-18.15.3.tgz",
+ "integrity": "sha512-p6ua9zBxz5otCmbpb5D3U4B5Nanw6Pk3PPyX05xnxbB/fRv71N7CPmORg7uAD5P70T0xmx1pzAx/FUfa5X+3cw==",
+ "dev": true
+ },
+ "node_modules/minimist": {
+ "version": "1.2.8",
+ "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz",
+ "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==",
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ }
+ },
+ "dependencies": {
+ "@types/node": {
+ "version": "18.15.3",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-18.15.3.tgz",
+ "integrity": "sha512-p6ua9zBxz5otCmbpb5D3U4B5Nanw6Pk3PPyX05xnxbB/fRv71N7CPmORg7uAD5P70T0xmx1pzAx/FUfa5X+3cw==",
+ "dev": true
+ },
+ "minimist": {
+ "version": "1.2.8",
+ "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz",
+ "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA=="
+ }
+ }
+}
diff --git a/backup/package.json b/backup/package.json
index 5aa71af7..419cac47 100644
--- a/backup/package.json
+++ b/backup/package.json
@@ -13,8 +13,12 @@
"private": true,
"license": "MIT",
"dependencies": {
- "lodash": "^4.17.21",
- "minimist": "^1.2.8",
- "node-fetch": "^3.3.1"
+ "minimist": "^1.2.8"
+ },
+ "devDependencies": {
+ "@types/node": "^18.15.3"
+ },
+ "engines": {
+ "node": ">= 18"
}
}
diff --git a/backup/yarn.lock b/backup/yarn.lock
deleted file mode 100644
index 0139be48..00000000
--- a/backup/yarn.lock
+++ /dev/null
@@ -1,52 +0,0 @@
-# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
-# yarn lockfile v1
-
-
-data-uri-to-buffer@^4.0.0:
- version "4.0.0"
- resolved "https://registry.yarnpkg.com/data-uri-to-buffer/-/data-uri-to-buffer-4.0.0.tgz#b5db46aea50f6176428ac05b73be39a57701a64b"
- integrity sha512-Vr3mLBA8qWmcuschSLAOogKgQ/Jwxulv3RNE4FXnYWRGujzrRWQI4m12fQqRkwX06C0KanhLr4hK+GydchZsaA==
-
-fetch-blob@^3.1.2, fetch-blob@^3.1.4:
- version "3.1.4"
- resolved "https://registry.yarnpkg.com/fetch-blob/-/fetch-blob-3.1.4.tgz#e8c6567f80ad7fc22fd302e7dcb72bafde9c1717"
- integrity sha512-Eq5Xv5+VlSrYWEqKrusxY1C3Hm/hjeAsCGVG3ft7pZahlUAChpGZT/Ms1WmSLnEAisEXszjzu/s+ce6HZB2VHA==
- dependencies:
- node-domexception "^1.0.0"
- web-streams-polyfill "^3.0.3"
-
-formdata-polyfill@^4.0.10:
- version "4.0.10"
- resolved "https://registry.yarnpkg.com/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz#24807c31c9d402e002ab3d8c720144ceb8848423"
- integrity sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==
- dependencies:
- fetch-blob "^3.1.2"
-
-lodash@^4.17.21:
- version "4.17.21"
- resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
- integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
-
-minimist@^1.2.8:
- version "1.2.8"
- resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c"
- integrity sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==
-
-node-domexception@^1.0.0:
- version "1.0.0"
- resolved "https://registry.yarnpkg.com/node-domexception/-/node-domexception-1.0.0.tgz#6888db46a1f71c0b76b3f7555016b63fe64766e5"
- integrity sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==
-
-node-fetch@^3.3.1:
- version "3.3.1"
- resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-3.3.1.tgz#b3eea7b54b3a48020e46f4f88b9c5a7430d20b2e"
- integrity sha512-cRVc/kyto/7E5shrWca1Wsea4y6tL9iYJE5FBCius3JQfb/4P4I295PfhgbJQBLTx6lATE4z+wK0rPM4VS2uow==
- dependencies:
- data-uri-to-buffer "^4.0.0"
- fetch-blob "^3.1.4"
- formdata-polyfill "^4.0.10"
-
-web-streams-polyfill@^3.0.3:
- version "3.2.0"
- resolved "https://registry.yarnpkg.com/web-streams-polyfill/-/web-streams-polyfill-3.2.0.tgz#a6b74026b38e4885869fb5c589e90b95ccfc7965"
- integrity sha512-EqPmREeOzttaLRm5HS7io98goBgZ7IVz79aDvqjD0kYXLtFZTc0T/U6wHTPKyIjb+MdN7DFIIX6hgdBEpWmfPA==