mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: add fixSorage
This commit is contained in:
7 files changed
+88
-22
No files matched your search
@@ -10,7 +10,7 @@
|
||||
"react-dnd": "^16.0.1",
|
||||
"react-dnd-html5-backend": "^16.0.1",
|
||||
"react-toastify": "^11.0.5",
|
||||
"schemastery-react": "^0.1.2"
|
||||
"schemastery-react": "^0.1.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/diff": "^8.0.0",
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/* eslint-disable no-await-in-loop */
|
||||
import { resolve } from 'path';
|
||||
import {
|
||||
existsSync, mkdir, readdir, rename, rmdir,
|
||||
} from 'fs-extra';
|
||||
import Schema from 'schemastery';
|
||||
import { Context } from '../context';
|
||||
|
||||
export const apply = (ctx: Context) => ctx.addScript(
|
||||
'fixStorage', 'Rename all files to lowercase',
|
||||
Schema.object({}),
|
||||
async () => {
|
||||
const config = await ctx.get('storage').status();
|
||||
console.log(config);
|
||||
if (config.type !== 'Local') throw new Error('Only local storage is supported');
|
||||
const dir = (config as any).dir;
|
||||
if (!dir) throw new Error('Storage dir not found');
|
||||
const files = await readdir(dir);
|
||||
for (const file of files) {
|
||||
let inner = await readdir(resolve(dir, file));
|
||||
if (file.toLowerCase() !== file && !existsSync(resolve(dir, file.toLowerCase()))) {
|
||||
await mkdir(resolve(dir, file.toLowerCase()));
|
||||
console.log('+: ', resolve(dir, file.toLowerCase()));
|
||||
}
|
||||
for (const f of inner) {
|
||||
if (resolve(dir, file, f) === resolve(dir, file.toLowerCase(), f.toLowerCase())) continue;
|
||||
await rename(resolve(dir, file, f), resolve(dir, file.toLowerCase(), f.toLowerCase()));
|
||||
console.log('R: ', resolve(dir, file, f), '->', resolve(dir, file.toLowerCase(), f.toLowerCase()));
|
||||
}
|
||||
inner = await readdir(resolve(dir, file));
|
||||
if (!inner.length) {
|
||||
await rmdir(resolve(dir, file));
|
||||
console.log('-: ', resolve(dir, file));
|
||||
}
|
||||
}
|
||||
const coll = ctx.get('db').collection('storage');
|
||||
while (true) {
|
||||
let hasItem = false;
|
||||
for await (const t of coll.find({ $or: [{ _id: /[A-Z]/ }, { link: /[A-Z]/ }] })) {
|
||||
hasItem = true;
|
||||
await coll.insertOne({
|
||||
...t,
|
||||
_id: t._id.toLowerCase(),
|
||||
...(t.link ? { link: t.link.toLowerCase() } : {}),
|
||||
});
|
||||
await coll.deleteOne({ _id: t._id });
|
||||
console.log('Q: ', t._id, '->', t._id.toLowerCase());
|
||||
}
|
||||
if (!hasItem) break;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
);
|
||||
@@ -387,6 +387,7 @@ class LocalStorageService {
|
||||
status: !this.error,
|
||||
error: this.error,
|
||||
bucket: 'Hydro',
|
||||
dir: this.config.path,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,16 +12,16 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@blueprintjs/core": "^5.19.0",
|
||||
"@fontsource/dm-mono": "^5.2.5",
|
||||
"@fontsource/dm-mono": "^5.2.6",
|
||||
"@fontsource/fira-code": "^5.2.6",
|
||||
"@fontsource/inconsolata": "^5.2.5",
|
||||
"@fontsource/jetbrains-mono": "^5.2.5",
|
||||
"@fontsource/pt-mono": "^5.2.5",
|
||||
"@fontsource/inconsolata": "^5.2.6",
|
||||
"@fontsource/jetbrains-mono": "^5.2.6",
|
||||
"@fontsource/pt-mono": "^5.2.6",
|
||||
"@fontsource/roboto-mono": "^5.2.6",
|
||||
"@fontsource/source-code-pro": "^5.2.6",
|
||||
"@fontsource/ubuntu-mono": "^5.2.5",
|
||||
"@fontsource/ubuntu-mono": "^5.2.6",
|
||||
"@hydrooj/utils": "workspace:^",
|
||||
"@sentry/browser": "^9.25.1",
|
||||
"@sentry/browser": "^9.27.0",
|
||||
"@sentry/webpack-plugin": "^3.5.0",
|
||||
"@simplewebauthn/browser": "13.1.0",
|
||||
"@svgr/webpack": "^8.1.0",
|
||||
@@ -50,8 +50,8 @@
|
||||
"clipboard": "^2.0.11",
|
||||
"copy-webpack-plugin": "^13.0.0",
|
||||
"cordis": "4.0.0-beta.5",
|
||||
"core-js": "^3.42.0",
|
||||
"core-js-compat": "^3.42.0",
|
||||
"core-js": "^3.43.0",
|
||||
"core-js-compat": "^3.43.0",
|
||||
"css-loader": "^7.1.2",
|
||||
"diff": "^8.0.2",
|
||||
"diff-dom": "^5.2.0",
|
||||
@@ -101,7 +101,6 @@
|
||||
"sass": "^1.89.1",
|
||||
"sass-loader": "^16.0.5",
|
||||
"schemastery": "^3.16.1",
|
||||
"schemastery-react": "^0.1.2",
|
||||
"shorty.js": "^1.0.1",
|
||||
"slideout": "^1.0.1",
|
||||
"sticky-kit": "^1.1.3",
|
||||
|
||||
Reference in new issue
Block a user