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

+4 -5
View File
@@ -15,7 +15,7 @@ import {
Handler, param, post, requireSudo, Types,
} from '../service/server';
import { encodeRFC5987ValueChars } from '../service/storage';
import { md5, sortFiles } from '../utils';
import { sortFiles } from '../utils';
class SwitchLanguageHandler extends Handler {
noCheckPermView = true;
@@ -108,10 +108,9 @@ export class StorageHandler extends Handler {
@param('filename', Types.Filename, true)
@param('expire', Types.UnsignedInt)
@param('secret', Types.String)
async get(domainId: string, target: string, filename = '', expire: number, secret: string) {
const expected = md5(`${target}/${expire}/${this.ctx.config.get('file.secret')}`);
async get({ }, target: string, filename = '', expire: number, secret: string) {
if (expire < Date.now()) throw new AccessDeniedError();
if (secret !== expected) throw new AccessDeniedError();
if (!(await this.ctx.get('storage')?.isLinkValid?.(`${target}/${expire}/${secret}`))) throw new AccessDeniedError();
this.response.body = await storage.get(target);
this.response.type = (target.endsWith('.out') || target.endsWith('.ans'))
? 'text/plain'
@@ -123,7 +122,7 @@ export class StorageHandler extends Handler {
export class SwitchAccountHandler extends Handler {
@requireSudo
@param('uid', Types.Int)
async get(domainId: string, uid: number) {
async get({ }, uid: number) {
this.session.sudoUid = this.user._id;
this.session.uid = uid;
this.back();