| … | … | @@ -771,21 +771,39 @@ export class Router { |
| 771 | 771 | async _filePreview (params) { |
| 772 | 772 | if (!params.roomId) throw new Error('Missing required param: roomId') |
| 773 | 773 | if (!params.fileId) throw new Error('Missing required param: fileId') |
| 774 | | // getFileEntry is broken — use getLocalFiles + search |
| 774 | |
| 775 | // getLocalFiles returns raw DB entries (without httpLinks) |
| 775 | 776 | const files = await this.backend.api.core.getLocalFiles(params.roomId) |
| 776 | 777 | const entries = Array.isArray(files) ? files : (files?.data || files?.entries || []) |
| 778 | |
| 779 | // Match file by blob ID — handle Buffer vs string comparison |
| 780 | const targetId = String(params.fileId) |
| 777 | 781 | const entry = entries.find(f => { |
| 778 | | const id = f.id || f.fileId || f.pointer?.externalBlob?.id |
| 779 | | return id === params.fileId |
| 782 | const fileObj = f.file || f |
| 783 | const blobId = fileObj?.pointer?.externalBlob?.id |
| 784 | if (!blobId) return false |
| 785 | const idStr = Buffer.isBuffer(blobId) ? blobId.toString('hex') : String(blobId) |
| 786 | return idStr === targetId |
| 780 | 787 | }) |
| 781 | 788 | if (!entry) throw new Error('File not found: ' + params.fileId) |
| 789 | |
| 790 | // Generate httpLink using FileManager's blob server |
| 791 | const fileObj = entry.file || entry |
| 792 | let httpLink = '' |
| 793 | try { |
| 794 | httpLink = String(await this.core.files.getFileLink(entry.roomKey, fileObj) || '') |
| 795 | } catch (err) { |
| 796 | console.error('[keet-daemon] getFileLink error:', err.message) |
| 797 | } |
| 798 | |
| 799 | const meta = fileObj?.metadata || {} |
| 782 | 800 | return { |
| 783 | | name: entry.fileName || entry.name || 'file', |
| 784 | | type: entry.mimeType || entry.type || '', |
| 785 | | size: entry.size || 0, |
| 786 | | httpLink: entry.httpLink || '', |
| 787 | | fullHttpLink: entry.httpLink || '', |
| 788 | | dimensions: entry.dimensions || null |
| 801 | name: meta.name || 'file', |
| 802 | type: meta.mimetype || '', |
| 803 | size: meta.size || 0, |
| 804 | httpLink, |
| 805 | fullHttpLink: httpLink, |
| 806 | dimensions: meta.dimensions || null |
| 789 | 807 | } |
| 790 | 808 | } |
| 791 | 809 | |