48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
import type { PrismaService } from '../../common/prisma/prisma.module';
|
|
|
|
export type OssActorRef = {
|
|
refType: string;
|
|
refId: bigint;
|
|
};
|
|
|
|
export function ossActorRefFromAuth(
|
|
actorType?: string,
|
|
actorId?: bigint,
|
|
): OssActorRef | undefined {
|
|
if (!actorType || actorId == null) return undefined;
|
|
return { refType: actorType, refId: actorId };
|
|
}
|
|
|
|
type LogOssUploadInput = {
|
|
scene: 'UPLOAD_PUT_OBJECT' | 'UPLOAD_TOKEN';
|
|
requestBody?: Record<string, unknown>;
|
|
responseBody?: Record<string, unknown>;
|
|
externalNo?: string;
|
|
status: 'SUCCESS' | 'FAILED';
|
|
errorMessage?: string;
|
|
actorRef?: OssActorRef;
|
|
};
|
|
|
|
export async function logOssUpload(prisma: PrismaService, input: LogOssUploadInput) {
|
|
try {
|
|
const row = await prisma.logThirdParty.create({
|
|
data: {
|
|
provider: 'ALIYUN_OSS',
|
|
scene: input.scene,
|
|
refType: input.actorRef?.refType,
|
|
refId: input.actorRef?.refId,
|
|
requestBody: input.requestBody as never,
|
|
responseBody: input.responseBody as never,
|
|
externalNo: input.externalNo?.slice(0, 128),
|
|
status: input.status,
|
|
errorMessage: input.errorMessage?.slice(0, 512),
|
|
},
|
|
});
|
|
return row.id;
|
|
} catch (err) {
|
|
// 日志表/枚举未就绪时不阻断上传主流程
|
|
console.error('[oss-upload-log] write failed:', err instanceof Error ? err.message : err);
|
|
return null;
|
|
}
|
|
}
|