core: fix builtin storage service

This commit is contained in:
undefined committed 2025-03-09 17:47:11 +08:00
1 parent 1a7b08e56e
commit 97ef575644
3 files changed
+39 -28

No files matched your search

+16
View File
@@ -262,6 +262,10 @@ class RemoteStorageService {
return url;
}
async isLinkValid(_: string) {
return false;
}
async signUpload(target: string, size: number) {
const client = this.alternatives.user || this.client;
const { url, fields } = await createPresignedPost(client, {
@@ -365,6 +369,12 @@ class LocalStorageService {
return `/${url.toString().split('localhost/')[1]}`;
}
async isLinkValid(link: string) {
const [target, expire, secret] = link.split('/');
const expected = md5(`${target}/${expire}/${this.config.secret}`);
return expected === secret;
}
async signUpload() {
throw new Error('Not implemented');
}
@@ -416,6 +426,12 @@ export async function apply(ctx: Context, config: ReturnType<typeof FileSetting>
ctx.set('storage', service);
}
declare module '../context' {
interface Context {
storage: RemoteStorageService | LocalStorageService;
}
}
/** @deprecated use ctx.storage instead */
const serviceProxy = new Proxy({}, {
get(self, key) {