mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-03 06:24:30 +00:00
feat(storage): add archive storage support for assets (#514)
* feat(storage): add archive storage support for assets * fix(webui): show archive icon in front of file name in breadcrumb bar * fix(webui): display archive icon in breadcrumbs when restoring * refactor(transcode): simplify restore asset workflow to single while loop * docs(configuration): add archive storage documentation and readme entries * fix(webui): show archive icon in front of version names and prevent version card overflow * fix(webui): fix overflow in manage versions dialog scroll area * fix(webui): prevent manage versions dialog overflow on long file names * docs(configuration): fix archive storage environment variables and defaults * fix(storage): address code review findings for archive storage
This commit is contained in:
@@ -57,7 +57,7 @@ export class EmbeddingService {
|
||||
const candidateAssets = await prisma.asset.findMany({
|
||||
where: {
|
||||
isDeleted: false,
|
||||
status: 'processed',
|
||||
status: { in: ['processed', 'archived'] },
|
||||
type: { in: ['file', 'version_stack'] },
|
||||
project: { teamId: { in: activeTeamIds } },
|
||||
},
|
||||
|
||||
@@ -106,5 +106,34 @@ describe('SqlQueryBuilder', () => {
|
||||
)
|
||||
expect(query.values).toEqual(['custom_field"test', 'hello'])
|
||||
})
|
||||
|
||||
it('isArchived eq true matches archived files and version stacks whose latest version is archived', () => {
|
||||
const builder = new SqlQueryBuilder()
|
||||
.from(Prisma.sql`assets a`)
|
||||
.addSearchConditions('AND', [{ field: 'isArchived', operator: 'eq', value: true }])
|
||||
|
||||
const query = builder.build()
|
||||
expect(query.text).toContain(
|
||||
`a."type" = 'file'::"AssetType" AND a."status" = 'archived'::"AssetStatus"`,
|
||||
)
|
||||
})
|
||||
|
||||
it('isArchived eq false matches non-archived files and version stacks', () => {
|
||||
const builder = new SqlQueryBuilder()
|
||||
.from(Prisma.sql`assets a`)
|
||||
.addSearchConditions('AND', [{ field: 'isArchived', operator: 'eq', value: false }])
|
||||
|
||||
const query = builder.build()
|
||||
expect(query.text).toContain(
|
||||
`a."type" = 'file'::"AssetType" AND a."status" != 'archived'::"AssetStatus"`,
|
||||
)
|
||||
})
|
||||
|
||||
it('throws an error for unsupported isArchived operators', () => {
|
||||
const builder = new SqlQueryBuilder().from(Prisma.sql`assets a`)
|
||||
expect(() =>
|
||||
builder.addSearchConditions('AND', [{ field: 'isArchived', operator: 'gt', value: true }]),
|
||||
).toThrow('Unsupported operator for isArchived field: gt')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -285,6 +285,42 @@ export class SqlQueryBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
if (field === 'isArchived' || field === 'is_archived') {
|
||||
if (operator !== 'eq' && operator !== 'neq') {
|
||||
throw new Error(`Unsupported operator for isArchived field: ${operator}`)
|
||||
}
|
||||
const rawBool = value === true || value === 'true' || value === 1 || value === '1'
|
||||
const wantArchived = operator === 'neq' ? !rawBool : rawBool
|
||||
if (wantArchived) {
|
||||
return Prisma.sql`(
|
||||
(a."type" = 'file'::"AssetType" AND a."status" = 'archived'::"AssetStatus")
|
||||
OR (
|
||||
a."type" = 'version_stack'::"AssetType"
|
||||
AND (
|
||||
SELECT v."status" FROM assets v
|
||||
WHERE v."parent_id" = a."id" AND v."is_deleted" = false
|
||||
ORDER BY v."sort_index" ASC LIMIT 1
|
||||
) = 'archived'::"AssetStatus"
|
||||
)
|
||||
)`
|
||||
}
|
||||
return Prisma.sql`(
|
||||
(a."type" = 'file'::"AssetType" AND a."status" != 'archived'::"AssetStatus")
|
||||
OR (
|
||||
a."type" = 'version_stack'::"AssetType"
|
||||
AND COALESCE(
|
||||
(
|
||||
SELECT v."status"::text FROM assets v
|
||||
WHERE v."parent_id" = a."id" AND v."is_deleted" = false
|
||||
ORDER BY v."sort_index" ASC LIMIT 1
|
||||
),
|
||||
''
|
||||
) != 'archived'
|
||||
)
|
||||
OR a."type" NOT IN ('file'::"AssetType", 'version_stack'::"AssetType")
|
||||
)`
|
||||
}
|
||||
|
||||
if (
|
||||
field === 'createdAt' ||
|
||||
field === 'updatedAt' ||
|
||||
|
||||
Reference in New Issue
Block a user