feat(asset): decouple logical assets from physical storage with StorageKey and implement O(1) copy

This commit is contained in:
yiling
2026-05-25 00:52:45 +08:00
parent c5fba746be
commit 5dc3bdb38e
33 changed files with 2203 additions and 273 deletions
+5 -3
View File
@@ -25,9 +25,11 @@ export class SkillService {
} else if (req.assetId) {
const asset = await this.prismaClient.asset.findUnique({
where: { id: req.assetId },
include: { storageKey: true },
})
if (!asset || !asset.key) throw new Error('Asset not found or has no key')
const { buffer } = await s3Service.getObject(process.env.S3_BUCKET || 'shumai', asset.key)
const key = asset?.storageKey?.key
if (!asset || !key) throw new Error('Asset not found or has no key')
const { buffer } = await s3Service.getObject(process.env.S3_BUCKET || 'shumai', key)
zipBuffer = buffer
} else {
throw new Error('Either assetId or githubUrl must be provided')
@@ -68,7 +70,7 @@ export class SkillService {
const skillAsset = await this.prismaClient.asset.create({
data: {
name: `${name}.zip`,
key: assetKey,
storageKey: { create: { key: assetKey } },
type: 'file',
mediaType: 'application/zip',
sizeByte: repackedZip.length,