feat(server): search blob names from indexer (#12822)

#### PR Dependency Tree


* **PR #12822** 👈

This tree was auto-generated by
[Charcoal](https://github.com/danerwilliams/charcoal)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Added the ability to search for blob names by their IDs within a
workspace.
- **Tests**
- Introduced new test cases and snapshot tests to validate searching
blob names and reading filenames from document snapshots.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
fengmk2
2025-06-16 16:34:23 +08:00
committed by GitHub
parent 4f75111055
commit c0c813edfd
9 changed files with 282 additions and 1 deletions
@@ -646,6 +646,93 @@ Generated by [AVA](https://avajs.dev).
title: 'Write, Draw, Plan all at Once.',
}
## can read blob filename from doc snapshot
> Snapshot 1
{
blocks: [
{
additional: {
displayMode: 'edgeless',
},
blockId: '4YHKIhPzAK',
content: 'index file name',
docId: 'doc-0',
flavour: 'affine:page',
yblock: {
'prop:title': 'index file name',
'sys:children': [
'WypcCGdupE',
'hZ1-cdLW5e',
],
'sys:flavour': 'affine:page',
'sys:id': '4YHKIhPzAK',
'sys:version': 2,
},
},
{
additional: {
displayMode: 'edgeless',
},
blockId: 'WypcCGdupE',
content: [],
docId: 'doc-0',
flavour: 'affine:surface',
parentBlockId: '4YHKIhPzAK',
parentFlavour: 'affine:page',
yblock: {
'prop:elements': {
type: '$blocksuite:internal:native$',
value: {},
},
'sys:children': [],
'sys:flavour': 'affine:surface',
'sys:id': 'WypcCGdupE',
'sys:version': 5,
},
},
{
additional: {
displayMode: 'page',
noteBlockId: 'hZ1-cdLW5e',
},
blob: [
'ldZMrM4PDlsNG4Q4YvCsz623h6TKu4qI9_FpTqIypfw=',
],
blockId: 'tfz1yFZdnn',
content: 'test file name here.txt',
docId: 'doc-0',
flavour: 'affine:attachment',
parentBlockId: 'hZ1-cdLW5e',
parentFlavour: 'affine:note',
yblock: {
'prop:embed': false,
'prop:footnoteIdentifier': null,
'prop:index': 'a0',
'prop:lockedBySelf': false,
'prop:meta:createdAt': 1750036953927,
'prop:meta:createdBy': '46ce597c-098a-4c61-a106-ce79827ec1de',
'prop:meta:updatedAt': 1750036953928,
'prop:meta:updatedBy': '46ce597c-098a-4c61-a106-ce79827ec1de',
'prop:name': 'test file name here.txt',
'prop:rotate': 0,
'prop:size': 3,
'prop:sourceId': 'ldZMrM4PDlsNG4Q4YvCsz623h6TKu4qI9_FpTqIypfw=',
'prop:style': 'horizontalThin',
'prop:type': 'text/plain',
'prop:xywh': '[0,0,0,0]',
'sys:children': [],
'sys:flavour': 'affine:attachment',
'sys:id': 'tfz1yFZdnn',
'sys:version': 1,
},
},
],
summary: '',
title: 'index file name',
}
## can read all blocks from doc snapshot without workspace snapshot
> Snapshot 1
@@ -56,6 +56,23 @@ test('can read all blocks from doc snapshot', async t => {
});
});
test('can read blob filename from doc snapshot', async t => {
const docSnapshot = await module.create(Mockers.DocSnapshot, {
workspaceId: workspace.id,
user: owner,
snapshotFile: 'test-doc-with-blob.snapshot.bin',
});
const result = await readAllBlocksFromDocSnapshot(
workspace.id,
'doc-0',
docSnapshot.blob
);
// NOTE: avoid snapshot result directly, because it will cause hanging
t.snapshot(JSON.parse(JSON.stringify(result)));
});
test('can read all blocks from doc snapshot without workspace snapshot', async t => {
const doc = await models.doc.get(workspace.id, docSnapshot.id);
t.truthy(doc);