feat: 新增aspect:presignFile用于私有桶的预签名下载
This commit is contained in:
parent
3fa730cfb1
commit
14d593cc89
|
|
@ -746,5 +746,17 @@ export type AspectDict<ED extends EntityDict> = {
|
|||
mergeChunkedUpload: (params: {
|
||||
extraFileId: string;
|
||||
}, context: BackendRuntimeContext<ED>) => Promise<void>;
|
||||
/**
|
||||
* 对文件进行预签名得到请求地址等信息
|
||||
* @param params 包含文件信息、请求方式等
|
||||
*/
|
||||
presignFile: (params: {
|
||||
extraDileId: string;
|
||||
method?: 'GET' | 'PUT' | 'POST' | 'DELETE';
|
||||
}, context: BackendRuntimeContext<ED>) => Promise<{
|
||||
url: string;
|
||||
headers?: Record<string, string | string[]>;
|
||||
formdata?: Record<string, any>;
|
||||
}>;
|
||||
};
|
||||
export default AspectDict;
|
||||
|
|
|
|||
|
|
@ -22,3 +22,11 @@ context: BRC<ED>): Promise<{
|
|||
export declare function mergeChunkedUpload<ED extends EntityDict>(params: {
|
||||
extraFileId: string;
|
||||
}, context: BRC<ED>): Promise<void>;
|
||||
export declare function presignFile<ED extends EntityDict>(params: {
|
||||
extraFileId: string;
|
||||
method?: 'GET' | 'PUT' | 'POST' | 'DELETE';
|
||||
}, context: BRC<ED>): Promise<{
|
||||
url: string;
|
||||
headers?: Record<string, string | string[]>;
|
||||
formdata?: Record<string, any>;
|
||||
}>;
|
||||
|
|
|
|||
|
|
@ -109,3 +109,21 @@ export async function mergeChunkedUpload(params, context) {
|
|||
throw err;
|
||||
}
|
||||
}
|
||||
export async function presignFile(params, context) {
|
||||
const { extraFileId, method = 'GET' } = params;
|
||||
assert(extraFileId, 'extraFileId不能为空');
|
||||
const [extrafile] = await context.select('extraFile', {
|
||||
data: {
|
||||
...extraFileProjection,
|
||||
application: {
|
||||
...applicationProjection,
|
||||
},
|
||||
},
|
||||
filter: {
|
||||
id: extraFileId,
|
||||
}
|
||||
}, { dontCollect: true });
|
||||
assert(extrafile, `找不到id为${extraFileId}的extraFile记录`);
|
||||
const cos = getCosBackend(extrafile.origin);
|
||||
return await cos.presignFile(method, extrafile.application, extrafile, context);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { bindByEmail, bindByMobile, loginByAccount, loginByEmail, loginByMobile, loginWechat, loginWechatMp, loginWechatNative, syncUserInfoWechatMp, sendCaptchaByMobile, sendCaptchaByEmail, switchTo, refreshWechatPublicUserInfo, getWechatMpUserPhoneNumber, logout, loginByWechat, wakeupParasite, refreshToken, verifyPassword, loginWebByMpToken, setUserAvatarFromWechat } from './token';
|
||||
import { getInfoByUrl, mergeChunkedUpload } from './extraFile';
|
||||
import { getInfoByUrl, mergeChunkedUpload, presignFile } from './extraFile';
|
||||
import { getApplication, signatureJsSDK, uploadWechatMedia, batchGetArticle, getArticle, batchGetMaterialList, getMaterial, deleteMaterial } from './application';
|
||||
import { updateConfig, updateApplicationConfig, updateStyle } from './config';
|
||||
import { syncWechatTemplate, getMessageType } from './template';
|
||||
|
|
@ -87,6 +87,7 @@ declare const aspectDict: {
|
|||
authorize: typeof authorize;
|
||||
setUserAvatarFromWechat: typeof setUserAvatarFromWechat;
|
||||
mergeChunkedUpload: typeof mergeChunkedUpload;
|
||||
presignFile: typeof presignFile;
|
||||
};
|
||||
export default aspectDict;
|
||||
export { AspectDict } from './AspectDict';
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { bindByEmail, bindByMobile, loginByAccount, loginByEmail, loginByMobile, loginWechat, loginWechatMp, loginWechatNative, syncUserInfoWechatMp, sendCaptchaByMobile, sendCaptchaByEmail, switchTo, refreshWechatPublicUserInfo, getWechatMpUserPhoneNumber, logout, loginByWechat, wakeupParasite, refreshToken, verifyPassword, loginWebByMpToken, setUserAvatarFromWechat, } from './token';
|
||||
import { getInfoByUrl, mergeChunkedUpload } from './extraFile';
|
||||
import { getInfoByUrl, mergeChunkedUpload, presignFile } from './extraFile';
|
||||
import { getApplication, signatureJsSDK, uploadWechatMedia, batchGetArticle, getArticle, batchGetMaterialList, getMaterial, deleteMaterial, } from './application';
|
||||
import { updateConfig, updateApplicationConfig, updateStyle } from './config';
|
||||
import { syncWechatTemplate, getMessageType } from './template';
|
||||
|
|
@ -87,6 +87,8 @@ const aspectDict = {
|
|||
createOAuthState,
|
||||
authorize,
|
||||
setUserAvatarFromWechat,
|
||||
// extraFile新增
|
||||
mergeChunkedUpload,
|
||||
presignFile,
|
||||
};
|
||||
export default aspectDict;
|
||||
|
|
|
|||
|
|
@ -746,5 +746,17 @@ export type AspectDict<ED extends EntityDict> = {
|
|||
mergeChunkedUpload: (params: {
|
||||
extraFileId: string;
|
||||
}, context: BackendRuntimeContext<ED>) => Promise<void>;
|
||||
/**
|
||||
* 对文件进行预签名得到请求地址等信息
|
||||
* @param params 包含文件信息、请求方式等
|
||||
*/
|
||||
presignFile: (params: {
|
||||
extraDileId: string;
|
||||
method?: 'GET' | 'PUT' | 'POST' | 'DELETE';
|
||||
}, context: BackendRuntimeContext<ED>) => Promise<{
|
||||
url: string;
|
||||
headers?: Record<string, string | string[]>;
|
||||
formdata?: Record<string, any>;
|
||||
}>;
|
||||
};
|
||||
export default AspectDict;
|
||||
|
|
|
|||
|
|
@ -22,3 +22,11 @@ context: BRC<ED>): Promise<{
|
|||
export declare function mergeChunkedUpload<ED extends EntityDict>(params: {
|
||||
extraFileId: string;
|
||||
}, context: BRC<ED>): Promise<void>;
|
||||
export declare function presignFile<ED extends EntityDict>(params: {
|
||||
extraFileId: string;
|
||||
method?: 'GET' | 'PUT' | 'POST' | 'DELETE';
|
||||
}, context: BRC<ED>): Promise<{
|
||||
url: string;
|
||||
headers?: Record<string, string | string[]>;
|
||||
formdata?: Record<string, any>;
|
||||
}>;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||
exports.getInfoByUrl = getInfoByUrl;
|
||||
exports.uploadExtraFile = uploadExtraFile;
|
||||
exports.mergeChunkedUpload = mergeChunkedUpload;
|
||||
exports.presignFile = presignFile;
|
||||
const tslib_1 = require("tslib");
|
||||
const WechatSDK_1 = tslib_1.__importDefault(require("oak-external-sdk/lib/WechatSDK"));
|
||||
const uuid_1 = require("oak-domain/lib/utils/uuid");
|
||||
|
|
@ -115,3 +116,21 @@ async function mergeChunkedUpload(params, context) {
|
|||
throw err;
|
||||
}
|
||||
}
|
||||
async function presignFile(params, context) {
|
||||
const { extraFileId, method = 'GET' } = params;
|
||||
(0, assert_1.assert)(extraFileId, 'extraFileId不能为空');
|
||||
const [extrafile] = await context.select('extraFile', {
|
||||
data: {
|
||||
...Projection_1.extraFileProjection,
|
||||
application: {
|
||||
...Projection_1.applicationProjection,
|
||||
},
|
||||
},
|
||||
filter: {
|
||||
id: extraFileId,
|
||||
}
|
||||
}, { dontCollect: true });
|
||||
(0, assert_1.assert)(extrafile, `找不到id为${extraFileId}的extraFile记录`);
|
||||
const cos = (0, index_backend_1.getCosBackend)(extrafile.origin);
|
||||
return await cos.presignFile(method, extrafile.application, extrafile, context);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { bindByEmail, bindByMobile, loginByAccount, loginByEmail, loginByMobile, loginWechat, loginWechatMp, loginWechatNative, syncUserInfoWechatMp, sendCaptchaByMobile, sendCaptchaByEmail, switchTo, refreshWechatPublicUserInfo, getWechatMpUserPhoneNumber, logout, loginByWechat, wakeupParasite, refreshToken, verifyPassword, loginWebByMpToken, setUserAvatarFromWechat } from './token';
|
||||
import { getInfoByUrl, mergeChunkedUpload } from './extraFile';
|
||||
import { getInfoByUrl, mergeChunkedUpload, presignFile } from './extraFile';
|
||||
import { getApplication, signatureJsSDK, uploadWechatMedia, batchGetArticle, getArticle, batchGetMaterialList, getMaterial, deleteMaterial } from './application';
|
||||
import { updateConfig, updateApplicationConfig, updateStyle } from './config';
|
||||
import { syncWechatTemplate, getMessageType } from './template';
|
||||
|
|
@ -87,6 +87,7 @@ declare const aspectDict: {
|
|||
authorize: typeof authorize;
|
||||
setUserAvatarFromWechat: typeof setUserAvatarFromWechat;
|
||||
mergeChunkedUpload: typeof mergeChunkedUpload;
|
||||
presignFile: typeof presignFile;
|
||||
};
|
||||
export default aspectDict;
|
||||
export { AspectDict } from './AspectDict';
|
||||
|
|
|
|||
|
|
@ -89,6 +89,8 @@ const aspectDict = {
|
|||
createOAuthState: oauth_1.createOAuthState,
|
||||
authorize: oauth_1.authorize,
|
||||
setUserAvatarFromWechat: token_1.setUserAvatarFromWechat,
|
||||
// extraFile新增
|
||||
mergeChunkedUpload: extraFile_1.mergeChunkedUpload,
|
||||
presignFile: extraFile_1.presignFile,
|
||||
};
|
||||
exports.default = aspectDict;
|
||||
|
|
|
|||
|
|
@ -1023,6 +1023,22 @@ export type AspectDict<ED extends EntityDict> = {
|
|||
},
|
||||
context: BackendRuntimeContext<ED>
|
||||
) => Promise<void>;
|
||||
|
||||
/**
|
||||
* 对文件进行预签名得到请求地址等信息
|
||||
* @param params 包含文件信息、请求方式等
|
||||
*/
|
||||
presignFile: (
|
||||
params: {
|
||||
extraDileId: string;
|
||||
method?: 'GET' | 'PUT' | 'POST' | 'DELETE';
|
||||
},
|
||||
context: BackendRuntimeContext<ED>
|
||||
) => Promise<{
|
||||
url: string;
|
||||
headers?: Record<string, string | string[]>;
|
||||
formdata?: Record<string, any>;
|
||||
}>;
|
||||
};
|
||||
|
||||
export default AspectDict;
|
||||
|
|
|
|||
|
|
@ -165,3 +165,39 @@ export async function mergeChunkedUpload<ED extends EntityDict>(
|
|||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
export async function presignFile<ED extends EntityDict>(
|
||||
params: {
|
||||
extraFileId: string;
|
||||
method?: 'GET' | 'PUT' | 'POST' | 'DELETE';
|
||||
},
|
||||
context: BRC<ED>
|
||||
): Promise<{
|
||||
url: string;
|
||||
headers?: Record<string, string | string[]>;
|
||||
formdata?: Record<string, any>;
|
||||
}> {
|
||||
const { extraFileId, method = 'GET' } = params;
|
||||
assert(extraFileId, 'extraFileId不能为空');
|
||||
const [extrafile] = await context.select('extraFile', {
|
||||
data: {
|
||||
...extraFileProjection,
|
||||
application: {
|
||||
...applicationProjection,
|
||||
},
|
||||
},
|
||||
filter: {
|
||||
id: extraFileId,
|
||||
}
|
||||
}, { dontCollect: true });
|
||||
|
||||
assert(extrafile, `找不到id为${extraFileId}的extraFile记录`);
|
||||
|
||||
const cos = getCosBackend(extrafile.origin!);
|
||||
return await cos.presignFile(
|
||||
method,
|
||||
extrafile.application!,
|
||||
extrafile as any,
|
||||
context as any
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import {
|
|||
loginWebByMpToken,
|
||||
setUserAvatarFromWechat,
|
||||
} from './token';
|
||||
import { getInfoByUrl, mergeChunkedUpload } from './extraFile';
|
||||
import { getInfoByUrl, mergeChunkedUpload,presignFile } from './extraFile';
|
||||
import {
|
||||
getApplication,
|
||||
signatureJsSDK,
|
||||
|
|
@ -144,7 +144,9 @@ const aspectDict = {
|
|||
createOAuthState,
|
||||
authorize,
|
||||
setUserAvatarFromWechat,
|
||||
// extraFile新增
|
||||
mergeChunkedUpload,
|
||||
presignFile,
|
||||
};
|
||||
|
||||
export default aspectDict;
|
||||
|
|
|
|||
Loading…
Reference in New Issue