Files
dashlibstorage/API.manifestattachment.md

160 lines
4.6 KiB
Markdown

# manifestattachment
This document is auto-generated from the JSDoc comments in `src/store` by running `npm run api-doc`.
## `manifestattachment.add`
*Source: `src/store/manifestattachment/add.js`*
Attaches a file to an existing manifest.
**Parameters**
| Name | Type | Description |
| --- | --- | --- |
| `googleAuthId` | `number` | The id of the Google auth user. |
| `manifestId` | `number` | The id of the manifest. |
| `input` | `object` | The file data. |
| `input.mimetype` | `string` | The MIME type of the file (e.g. `'application/pdf'`). |
| `input.name` | `string` | The file name. |
| `input.content` | `Buffer` | The file content. |
| `[input.sort]` | `number` | Optional display sort order. |
| `[input.hash]` | `string` | The file hash (auto-computed SHA-256 if omitted). |
| `[input.thumbavif]` | `Buffer` | Optional AVIF thumbnail buffer. |
| `[input.thumbx]` | `number` | Optional thumbnail width. |
| `[input.thumby]` | `number` | Optional thumbnail height. |
**Returns**
`Promise<{id: number, manifestId: number, fileId: number, sort: number, hash: string, mimetype: string, name: string, thumbavif: Buffer|null, thumbx: number|null, thumby: number|null}>` — The created attachment record.
**Throws**
`Error` — If the manifest is not found or file input is invalid.
**Example**
```js
const attachment = await store.manifestattachment.add(42, 1, {
mimetype: 'application/pdf',
name: 'invoice.pdf',
content: fileBuffer,
});
// => { id, manifestId, fileId, sort, hash, mimetype, name, thumbavif, thumbx, thumby }
```
## `manifestattachment.getById`
*Source: `src/store/manifestattachment/getById.js`*
Gets an attachment for a manifest by its attachment ID or file ID, including full file content.
**Parameters**
| Name | Type | Description |
| --- | --- | --- |
| `googleAuthId` | `number` | The id of the Google auth user. |
| `manifestId` | `number` | The manifest ID. |
| `id` | `number` | The attachment ID or file ID. |
**Returns**
`Promise<{id: number, manifestId: number, fileId: number, sort: number, hash: string, mimetype: string, name: string, content: Buffer, thumbavif: Buffer|null, thumbx: number|null, thumby: number|null}>` — The attachment record with binary content.
**Throws**
`Error` — If the manifest or attachment is not found, or user is not authorized.
**Example**
```js
const attachment = await store.manifestattachment.getById(42, 1, 5);
// => { id, manifestId, fileId, sort, hash, mimetype, name, content, thumbavif, thumbx, thumby }
```
## `manifestattachment.listByManifestId`
*Source: `src/store/manifestattachment/listByManifestId.js`*
Lists all attachments for a given manifest, without loading their full binary content.
**Parameters**
| Name | Type | Description |
| --- | --- | --- |
| `googleAuthId` | `number` | The id of the Google auth user. |
| `manifestId` | `number` | The manifest ID. |
**Returns**
`Promise<Array<{id: number, manifestId: number, fileId: number, sort: number, hash: string, mimetype: string, name: string, size: number, thumbavif: Buffer|null, thumbx: number|null, thumby: number|null}>>` — A list of attachment metadata objects.
**Throws**
`Error` — If the manifest is not found or the user is not authorized.
**Example**
```js
const attachments = await store.manifestattachment.listByManifestId(42, 1);
// => [{ id, manifestId, fileId, sort, hash, mimetype, name, size, thumbavif, thumbx, thumby }]
```
## `manifestattachment.order`
*Source: `src/store/manifestattachment/order.js`*
Reorders the attachments of a manifest.
**Parameters**
| Name | Type | Description |
| --- | --- | --- |
| `googleAuthId` | `number` | The id of the Google auth user. |
| `manifestId` | `number` | The manifest ID. |
| `input` | `object|Array<number>` | The reorder input or array of IDs. |
| `[input.ids]` | `Array<number>` | The attachment ids in their new order. |
**Returns**
`Promise<{ids: Array<number>}>` — The applied order.
**Throws**
`Error` — If the order is invalid.
**Example**
```js
const result = await store.manifestattachment.order(42, 1, { ids: [12, 10, 15] });
// => { ids: [12, 10, 15] }
```
## `manifestattachment.remove`
*Source: `src/store/manifestattachment/remove.js`*
Removes a file attachment from a manifest and deletes the underlying file.
**Parameters**
| Name | Type | Description |
| --- | --- | --- |
| `googleAuthId` | `number` | The id of the Google auth user. |
| `manifestId` | `number` | The manifest ID. |
| `id` | `number` | The attachment ID or file ID to remove. |
**Returns**
`Promise<void>`
**Throws**
`Error` — If the manifest or attachment is not found, or user is not authorized.
**Example**
```js
await store.manifestattachment.remove(42, 1, 5);
```