mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-08-12 02:29:00 +08:00
feat: Provide virtual disk operation API
This commit is contained in:
parent
cf35afcab2
commit
26e83798da
@ -38,6 +38,10 @@ try {
|
|||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
meta.script = $script;
|
meta.script = $script;
|
||||||
}
|
}
|
||||||
|
if (typeof $Plugin !== 'undefined') {
|
||||||
|
// eslint-disable-next-line no-undef
|
||||||
|
meta.plugin = $Plugin;
|
||||||
|
}
|
||||||
if (isNode) {
|
if (isNode) {
|
||||||
meta.node = {
|
meta.node = {
|
||||||
version: eval('process.version'),
|
version: eval('process.version'),
|
||||||
@ -53,9 +57,6 @@ try {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isGUIforCores) {
|
|
||||||
meta.plugin = Plugin;
|
|
||||||
}
|
|
||||||
// eslint-disable-next-line no-empty
|
// eslint-disable-next-line no-empty
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
|
1
backend/src/vendor/express.js
vendored
1
backend/src/vendor/express.js
vendored
@ -54,7 +54,6 @@ export default function express({ substore: $, port, host }) {
|
|||||||
// dispatch url to route
|
// dispatch url to route
|
||||||
const dispatch = (request, start = 0) => {
|
const dispatch = (request, start = 0) => {
|
||||||
let { method, url, headers, body } = request;
|
let { method, url, headers, body } = request;
|
||||||
console.log(url, method, headers, body);
|
|
||||||
headers = formatHeaders(headers);
|
headers = formatHeaders(headers);
|
||||||
if (/json/i.test(headers['content-type'])) {
|
if (/json/i.test(headers['content-type'])) {
|
||||||
body = JSON.parse(body);
|
body = JSON.parse(body);
|
||||||
|
45
backend/src/vendor/open-api.js
vendored
45
backend/src/vendor/open-api.js
vendored
@ -49,7 +49,8 @@ export class OpenAPI {
|
|||||||
this.cache = JSON.parse($prefs.valueForKey(this.name) || '{}');
|
this.cache = JSON.parse($prefs.valueForKey(this.name) || '{}');
|
||||||
if (isLoon || isSurge)
|
if (isLoon || isSurge)
|
||||||
this.cache = JSON.parse($persistentStore.read(this.name) || '{}');
|
this.cache = JSON.parse($persistentStore.read(this.name) || '{}');
|
||||||
|
if (isGUIforCores)
|
||||||
|
this.cache = JSON.parse(Plugins.$memory.get(this.name) || '{}');
|
||||||
if (isNode) {
|
if (isNode) {
|
||||||
// create a json for root cache
|
// create a json for root cache
|
||||||
const basePath =
|
const basePath =
|
||||||
@ -80,24 +81,6 @@ export class OpenAPI {
|
|||||||
this.cache = JSON.parse(this.node.fs.readFileSync(`${fpath}`));
|
this.cache = JSON.parse(this.node.fs.readFileSync(`${fpath}`));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isGUIforCores) {
|
|
||||||
const basePath = 'data/third/sub-store-v3';
|
|
||||||
this.cache = {};
|
|
||||||
this.root = {};
|
|
||||||
$Plugins
|
|
||||||
.ignoredError($Plugins.Readfile, `${basePath}/root.json`)
|
|
||||||
.then((text) => {
|
|
||||||
this.root = JSON.parse(text || '{}');
|
|
||||||
});
|
|
||||||
$Plugins
|
|
||||||
.ignoredError(
|
|
||||||
$Plugins.Readfile,
|
|
||||||
`${basePath}/${this.name}.json`,
|
|
||||||
)
|
|
||||||
.then((text) => {
|
|
||||||
this.cache = JSON.parse(text || '{}');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// store cache
|
// store cache
|
||||||
@ -105,6 +88,7 @@ export class OpenAPI {
|
|||||||
const data = JSON.stringify(this.cache, null, 2);
|
const data = JSON.stringify(this.cache, null, 2);
|
||||||
if (isQX) $prefs.setValueForKey(data, this.name);
|
if (isQX) $prefs.setValueForKey(data, this.name);
|
||||||
if (isLoon || isSurge) $persistentStore.write(data, this.name);
|
if (isLoon || isSurge) $persistentStore.write(data, this.name);
|
||||||
|
if (isGUIforCores) Plugins.$memory.set(this.name, data);
|
||||||
if (isNode) {
|
if (isNode) {
|
||||||
const basePath =
|
const basePath =
|
||||||
eval('process.env.SUB_STORE_DATA_BASE_PATH') || '.';
|
eval('process.env.SUB_STORE_DATA_BASE_PATH') || '.';
|
||||||
@ -122,18 +106,6 @@ export class OpenAPI {
|
|||||||
(err) => console.log(err),
|
(err) => console.log(err),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (isGUIforCores) {
|
|
||||||
const basePath = 'data/third/sub-store-v3';
|
|
||||||
$Plugins
|
|
||||||
.Writefile(`${basePath}/${this.name}.json`, data)
|
|
||||||
.catch((err) => console.log(err));
|
|
||||||
$Plugins
|
|
||||||
.Writefile(
|
|
||||||
`${basePath}/root.json`,
|
|
||||||
JSON.stringify(this.root, null, 2),
|
|
||||||
)
|
|
||||||
.catch((err) => console.log(err));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
write(data, key) {
|
write(data, key) {
|
||||||
@ -150,7 +122,7 @@ export class OpenAPI {
|
|||||||
this.root[key] = data;
|
this.root[key] = data;
|
||||||
}
|
}
|
||||||
if (isGUIforCores) {
|
if (isGUIforCores) {
|
||||||
this.root[key] = data;
|
return Plugins.$memory.set(key, data);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.cache[key] = data;
|
this.cache[key] = data;
|
||||||
@ -172,7 +144,7 @@ export class OpenAPI {
|
|||||||
return this.root[key];
|
return this.root[key];
|
||||||
}
|
}
|
||||||
if (isGUIforCores) {
|
if (isGUIforCores) {
|
||||||
return this.root[key];
|
return Plugins.$memory.get(key);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return this.cache[key];
|
return this.cache[key];
|
||||||
@ -193,7 +165,7 @@ export class OpenAPI {
|
|||||||
delete this.root[key];
|
delete this.root[key];
|
||||||
}
|
}
|
||||||
if (isGUIforCores) {
|
if (isGUIforCores) {
|
||||||
delete this.root[key];
|
return Plugins.$memory.remove(key);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
delete this.cache[key];
|
delete this.cache[key];
|
||||||
@ -410,12 +382,9 @@ export function HTTP(defaultOptions = { baseURL: '' }) {
|
|||||||
};
|
};
|
||||||
const request = requestHandler[method.toLowerCase()];
|
const request = requestHandler[method.toLowerCase()];
|
||||||
if (!request) reject('GUI.for.Cores未实现当前方法:' + method);
|
if (!request) reject('GUI.for.Cores未实现当前方法:' + method);
|
||||||
const body = ['put', 'post'].includes(method.toLowerCase())
|
|
||||||
? options.body
|
|
||||||
: {};
|
|
||||||
try {
|
try {
|
||||||
const { url, headers } = options;
|
const { url, headers } = options;
|
||||||
const response = await request(url, headers, body);
|
const response = await request(url, headers, options.body);
|
||||||
resolve({
|
resolve({
|
||||||
statusCode: response.status ?? 200,
|
statusCode: response.status ?? 200,
|
||||||
headers: response.header,
|
headers: response.header,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user