Skip to content

armgit / papra

Public Imported from GitHub
0

The minimalistic document archiving platform.

feat(server): add azure blob storage support (#261)

riskpoint-perdd8f194fd0cd
diff --git a/apps/papra-server/package.json b/apps/papra-server/package.json
index 469b6b36..8d96690c 100644
--- a/apps/papra-server/package.json
+++ b/apps/papra-server/package.json
@@ -31,6 +31,7 @@
"dependencies": {
"@aws-sdk/client-s3": "^3.722.0",
"@aws-sdk/lib-storage": "^3.722.0",
+ "@azure/storage-blob": "^12.27.0",
"@corentinth/chisels": "^1.1.0",
"@corentinth/friendly-ids": "^0.0.1",
"@crowlog/async-context-plugin": "^1.0.0",
diff --git a/apps/papra-server/src/modules/documents/storage/document-storage.config.ts b/apps/papra-server/src/modules/documents/storage/document-storage.config.ts
index 28a5ba76..ed16cb1d 100644
--- a/apps/papra-server/src/modules/documents/storage/document-storage.config.ts
+++ b/apps/papra-server/src/modules/documents/storage/document-storage.config.ts
@@ -1,5 +1,6 @@
import type { ConfigDefinition } from 'figue';
import { z } from 'zod';
+import { AZ_BLOB_STORAGE_DRIVER_NAME } from './drivers/az-blob/az-blob.storage-driver';
import { B2_STORAGE_DRIVER_NAME } from './drivers/b2/b2.storage-driver';
import { FS_STORAGE_DRIVER_NAME } from './drivers/fs/fs.storage-driver';
import { IN_MEMORY_STORAGE_DRIVER_NAME } from './drivers/memory/memory.storage-driver';
@@ -13,8 +14,8 @@ export const documentStorageConfig = {
env: 'DOCUMENT_STORAGE_MAX_UPLOAD_SIZE',
},
driver: {
- doc: `The driver to use for document storage, values can be one of: ${[FS_STORAGE_DRIVER_NAME, S3_STORAGE_DRIVER_NAME, IN_MEMORY_STORAGE_DRIVER_NAME, B2_STORAGE_DRIVER_NAME].map(x => `\`${x}\``).join(', ')}`,
- schema: z.enum([FS_STORAGE_DRIVER_NAME, S3_STORAGE_DRIVER_NAME, IN_MEMORY_STORAGE_DRIVER_NAME, B2_STORAGE_DRIVER_NAME]),
+ doc: `The driver to use for document storage, values can be one of: ${[FS_STORAGE_DRIVER_NAME, S3_STORAGE_DRIVER_NAME, IN_MEMORY_STORAGE_DRIVER_NAME, B2_STORAGE_DRIVER_NAME, AZ_BLOB_STORAGE_DRIVER_NAME].map(x => `\`${x}\``).join(', ')}`,
+ schema: z.enum([FS_STORAGE_DRIVER_NAME, S3_STORAGE_DRIVER_NAME, IN_MEMORY_STORAGE_DRIVER_NAME, B2_STORAGE_DRIVER_NAME, AZ_BLOB_STORAGE_DRIVER_NAME]),
default: FS_STORAGE_DRIVER_NAME,
env: 'DOCUMENT_STORAGE_DRIVER',
},
@@ -85,5 +86,25 @@ export const documentStorageConfig = {
env: 'DOCUMENT_STORAGE_B2_BUCKET_ID',
},
},
+ azureBlob: {
+ accountName: {
+ doc: 'The Azure Blob Storage account name',
+ schema: z.string(),
+ default: '',
+ env: 'DOCUMENT_STORAGE_AZURE_BLOB_ACCOUNT_NAME',
+ },
+ accountKey: {
+ doc: 'The Azure Blob Storage account key',
+ schema: z.string(),
+ default: '',
+ env: 'DOCUMENT_STORAGE_AZURE_BLOB_ACCOUNT_KEY',
+ },
+ containerName: {
+ doc: 'The Azure Blob Storage container name',
+ schema: z.string(),
+ default: '',
+ env: 'DOCUMENT_STORAGE_AZURE_BLOB_CONTAINER_NAME',
+ },
+ },
},
} as const satisfies ConfigDefinition;
diff --git a/apps/papra-server/src/modules/documents/storage/documents.storage.services.ts b/apps/papra-server/src/modules/documents/storage/documents.storage.services.ts
index 153af55d..294989c9 100644
--- a/apps/papra-server/src/modules/documents/storage/documents.storage.services.ts
+++ b/apps/papra-server/src/modules/documents/storage/documents.storage.services.ts
@@ -1,5 +1,6 @@
import type { Config } from '../../config/config.types';
import { createError } from '../../shared/errors/errors';
+import { AZ_BLOB_STORAGE_DRIVER_NAME, azBlobStorageDriverFactory } from './drivers/az-blob/az-blob.storage-driver';
import { B2_STORAGE_DRIVER_NAME, b2StorageDriverFactory } from './drivers/b2/b2.storage-driver';
import { FS_STORAGE_DRIVER_NAME, fsStorageDriverFactory } from './drivers/fs/fs.storage-driver';
import { IN_MEMORY_STORAGE_DRIVER_NAME, inMemoryStorageDriverFactory } from './drivers/memory/memory.storage-driver';
@@ -9,6 +10,7 @@ const storageDriverFactories = {
[FS_STORAGE_DRIVER_NAME]: fsStorageDriverFactory,
[S3_STORAGE_DRIVER_NAME]: s3StorageDriverFactory,
[IN_MEMORY_STORAGE_DRIVER_NAME]: inMemoryStorageDriverFactory,
+ [AZ_BLOB_STORAGE_DRIVER_NAME]: azBlobStorageDriverFactory,
[B2_STORAGE_DRIVER_NAME]: b2StorageDriverFactory,
};
diff --git a/apps/papra-server/src/modules/documents/storage/drivers/az-blob/az-blob.storage-driver.ts b/apps/papra-server/src/modules/documents/storage/drivers/az-blob/az-blob.storage-driver.ts
new file mode 100644
index 00000000..7fea94f6
--- /dev/null
+++ b/apps/papra-server/src/modules/documents/storage/drivers/az-blob/az-blob.storage-driver.ts
@@ -0,0 +1,38 @@
+import { Readable } from 'node:stream';
+import { BlobServiceClient, StorageSharedKeyCredential } from '@azure/storage-blob';
+
+import { createFileNotFoundError } from '../../document-storage.errors';
+import { defineStorageDriver } from '../drivers.models';
+
+export const AZ_BLOB_STORAGE_DRIVER_NAME = 'azure-blob' as const;
+
+export const azBlobStorageDriverFactory = defineStorageDriver(async ({ config }) => {
+ const { accountName, accountKey, containerName } = config.documentsStorage.drivers.azureBlob;
+
+ const blobServiceClient = new BlobServiceClient(`https://${accountName}.blob.core.windows.net`, new StorageSharedKeyCredential(accountName, accountKey));
+
+ return {
+ name: AZ_BLOB_STORAGE_DRIVER_NAME,
+ saveFile: async ({ file, storageKey }) => {
+ const containerClient = blobServiceClient.getContainerClient(containerName);
+ await containerClient.uploadBlockBlob(storageKey, Readable.fromWeb(file.stream()), file.size);
+ return { storageKey };
+ },
+ getFileStream: async ({ storageKey }) => {
+ const containerClient = blobServiceClient.getContainerClient(containerName);
+ const blockBlobClient = containerClient.getBlockBlobClient(storageKey);
+ const { readableStreamBody } = await blockBlobClient.download();
+
+ if (!readableStreamBody) {
+ throw createFileNotFoundError();
+ }
+
+ return { fileStream: Readable.toWeb(readableStreamBody as Readable) };
+ },
+ deleteFile: async ({ storageKey }) => {
+ const containerClient = blobServiceClient.getContainerClient(containerName);
+ const blockBlobClient = containerClient.getBlockBlobClient(storageKey);
+ await blockBlobClient.delete();
+ },
+ };
+});
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index f69efcc0..daf395e6 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -40,19 +40,19 @@ importers:
dependencies:
'@astrojs/starlight':
specifier: ^0.34.1
astro:
specifier: ^5.7.5
sharp:
specifier: ^0.32.5
version: 0.32.6
starlight-links-validator:
specifier: ^0.16.0
starlight-theme-rapide:
specifier: ^0.5.0
zod-to-json-schema:
specifier: ^3.24.5
version: 3.24.5([email protected])
@@ -164,7 +164,7 @@ importers:
unstorage:
specifier: ^1.14.4
- version: 1.15.0([email protected])
+ version: 1.15.0(@azure/[email protected])([email protected])
valibot:
specifier: 1.0.0-beta.10
version: 1.0.0-beta.10([email protected])
@@ -220,6 +220,9 @@ importers:
'@aws-sdk/lib-storage':
specifier: ^3.722.0
version: 3.758.0(@aws-sdk/[email protected])
+ '@azure/storage-blob':
+ specifier: ^12.27.0
+ version: 12.27.0
'@corentinth/chisels':
specifier: ^1.1.0
version: 1.1.0
@@ -686,6 +689,54 @@ packages:
resolution: {integrity: sha512-Zrjxi5qwGEcUsJ0ru7fRtW74WcTS0rbLcehoFB+rN1GRi2hbLcFaYs4PwVA5diLeAJH0gszv3x4Hr/S87MfbKQ==}
engines: {node: '>=18.0.0'}
+ '@azure/[email protected]':
+ resolution: {integrity: sha512-nBrLsEWm4J2u5LpAPjxADTlq3trDgVZZXHNKabeXZtpq3d3AbN/KGO82R87rdDz5/lYB024rtEf10/q0urNgsA==}
+ engines: {node: '>=18.0.0'}
+
+ '@azure/[email protected]':
+ resolution: {integrity: sha512-FPwHpZywuyasDSLMqJ6fhbOK3TqUdviZNF8OqRGA4W5Ewib2lEEZ+pBsYcBa88B2NGO/SEnYPGhyBqNlE8ilSw==}
+ engines: {node: '>=18.0.0'}
+
+ '@azure/[email protected]':
+ resolution: {integrity: sha512-/wGw8fJ4mdpJ1Cum7s1S+VQyXt1ihwKLzfabS1O/RDADnmzVc01dHn44qD0BvGH6KlZNzOMW95tEpKqhkCChPA==}
+ engines: {node: '>=18.0.0'}
+
+ '@azure/[email protected]':
+ resolution: {integrity: sha512-1kW8ZhN0CfbNOG6C688z5uh2yrzALE7dDXHiR9dY4vt+EbhGZQSbjDa5bQd2rf3X2pdWMsXbqbArxUyeNdvtmg==}
+ engines: {node: '>=18.0.0'}
+
+ '@azure/[email protected]':
+ resolution: {integrity: sha512-0YIpccoX8m/k00O7mDDMdJpbr6mf1yWo2dfmxt5A8XVZVVMz2SSKaEbMCeJRvgQ0IaSlqhjT47p4hVIRRy90xw==}
+ engines: {node: '>=18.0.0'}
+
+ '@azure/[email protected]':
+ resolution: {integrity: sha512-YKWi9YuCU04B55h25cnOYZHxXYtEvQEbKST5vqRga7hWY9ydd3FZHdeQF8pyh+acWZvppw13M/LMGx0LABUVMA==}
+ engines: {node: '>=18.0.0'}
+
+ '@azure/[email protected]':
+ resolution: {integrity: sha512-zHeoI3NCs53lLBbWNzQycjnYKsA1CVKlnzSNuSFcUDwBp8HHVObePxrM7HaX+Ha5Ks639H7chNC9HOaIhNS03w==}
+ engines: {node: '>=18.0.0'}
+
+ '@azure/[email protected]':
+ resolution: {integrity: sha512-UKTiEJPkWcESPYJz3X5uKRYyOcJD+4nYph+KpfdPRnQJVrZfk0KJgdnaAWKfhsBBtAf/D58Az4AvCJEmWgIBAg==}
+ engines: {node: '>=18.0.0'}
+
+ '@azure/[email protected]':
+ resolution: {integrity: sha512-DxOSLua+NdpWoSqULhjDyAZTXFdP/LKkqtYuxxz1SCN289zk3OG8UOpnCQAz/tygyACBtWp/BoO72ptK7msY8g==}
+ engines: {node: '>=18.0.0'}
+
+ '@azure/[email protected]':
+ resolution: {integrity: sha512-gT4H8mTaSXRz7eGTuQyq1aIJnJqeXzpOe9Ay7Z3FrCouer14CbV3VzjnJrNrQfbBpGBLO9oy8BmrY75A0p53cA==}
+ engines: {node: '>=18.0.0'}
+
+ '@azure/[email protected]':
+ resolution: {integrity: sha512-4IXXzcCdLdlXuCG+8UKEwLA1T1NHqUfanhXYHiQTn+6sfWCZXduqbtXDGceg3Ce5QxTGo7EqmbV6Bi+aqKuClQ==}
+ engines: {node: '>=18.0.0'}
+
+ '@azure/[email protected]':
+ resolution: {integrity: sha512-IQjj9RIzAKatmNca3D6bT0qJ+Pkox1WZGOg2esJF2YLHb45pQKOwGPIAV+w3rfgkj7zV3RMxpn/c6iftzSOZJQ==}
+ engines: {node: '>=18.0.0'}
+
resolution: {integrity: sha512-RJlIHRueQgwWitWgF8OdFYGZX328Ax5BCemNGlqHfplnRT9ESi8JkFlvaVYbS+UubVY6dpv87Fs2u5M29iNFVQ==}
engines: {node: '>=6.9.0'}
@@ -4778,6 +4829,10 @@ packages:
resolution: {integrity: sha512-xkjOecfnKGkSsOwtZ5Pz7Us/T6mrbPQrq0nh+aCO5V9nk5NLWmasAHumTKjiPJPWANe+kAZ84Jc8ooJkzZ88Sw==}
hasBin: true
+ resolution: {integrity: sha512-Kqq/ewnRACQ20e0BlQ5KqHRYWRBp7yv+jttK4Yj2yY+2ldgCoxJkrP1NHUhjypsJ+eQXlGJ/jebM3wa60s1rbQ==}
+ hasBin: true
+
resolution: {integrity: sha512-QKHXPW0hD8g4UET03SdOdunzSouc9N4AuHdsX8XNcTsuz+yYFILVNIX4l9yHABMhiEI9Db0JTTIpu0wB+Y1QQw==}
@@ -5903,6 +5958,7 @@ packages:
resolution: {integrity: sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==}
engines: {node: '>=10.5.0'}
+ deprecated: Use your platform's native DOMException instead
resolution: {integrity: sha512-8Mc2HhqPdlIfedsuZoc3yioPuzp6b+L5jRCRY1QzuWZh2EGJVQrGppC6V6cF0bLdbW0+O2YpqCA25aF/1lvipQ==}
@@ -6940,6 +6996,9 @@ packages:
resolution: {integrity: sha512-vrN+B7DBIoTTZjnPNewwhx6cBA/H+IS7rfW68n7XxC1y7uoiGQBxaKzqucGUgavX15dJgiGztLJ8vxuEzwqBdA==}
+ resolution: {integrity: sha512-YAT3K/sgpCUxhxNMrrdhtod3jckkpYwH6JAuwmUdXZsmzH1wUyzTMrrK2wYCEEqlKwrWDd35NeuUkbBy/1iK+Q==}
+
resolution: {integrity: sha512-/Q6ld50hKYPH3d/r6nr117TZkHR0w0kGGIVfpG9N6D8NymRPM9RqCUv4pRpJ62E5DqOYx2AFpbZMyCPnjQCnOw==}
@@ -7920,12 +7979,12 @@ snapshots:
transitivePeerDependencies:
- supports-color
dependencies:
'@astrojs/markdown-remark': 6.3.1
'@mdx-js/mdx': 3.1.0([email protected])
acorn: 8.14.1
es-module-lexer: 1.6.0
estree-util-visit: 2.0.0
hast-util-to-html: 9.0.5
@@ -7949,17 +8008,17 @@ snapshots:
stream-replace-string: 2.0.0
zod: 3.24.2
dependencies:
'@astrojs/markdown-remark': 6.3.1
'@astrojs/sitemap': 3.3.0
'@pagefind/default-ui': 1.3.0
'@types/hast': 3.0.4
'@types/js-yaml': 4.0.9
'@types/mdast': 4.0.4
bcp-47: 2.1.0
hast-util-from-html: 2.0.3
hast-util-select: 6.0.4
@@ -8463,6 +8522,96 @@ snapshots:
'@smithy/types': 4.1.0
tslib: 2.8.1
+ '@azure/[email protected]':
+ dependencies:
+ tslib: 2.8.1
+
+ '@azure/[email protected]':
+ dependencies:
+ '@azure/abort-controller': 2.1.2
+ '@azure/core-util': 1.11.0
+ tslib: 2.8.1
+
+ '@azure/[email protected]':
+ dependencies:
+ '@azure/abort-controller': 2.1.2
+ '@azure/core-auth': 1.9.0
+ '@azure/core-rest-pipeline': 1.19.1
+ '@azure/core-tracing': 1.2.0
+ '@azure/core-util': 1.11.0
+ '@azure/logger': 1.1.4
+ tslib: 2.8.1
+ transitivePeerDependencies:
+ - supports-color
+
+ '@azure/[email protected]':
+ dependencies:
+ '@azure/abort-controller': 2.1.2
+ '@azure/core-client': 1.9.3
+ '@azure/core-rest-pipeline': 1.19.1
+ transitivePeerDependencies:
+ - supports-color
+
+ '@azure/[email protected]':
+ dependencies:
+ '@azure/abort-controller': 2.1.2
+ '@azure/core-util': 1.11.0
+ '@azure/logger': 1.1.4
+ tslib: 2.8.1
+
+ '@azure/[email protected]':
+ dependencies:
+ tslib: 2.8.1
+
+ '@azure/[email protected]':
+ dependencies:
+ '@azure/abort-controller': 2.1.2
+ '@azure/core-auth': 1.9.0
+ '@azure/core-tracing': 1.2.0
+ '@azure/core-util': 1.11.0
+ '@azure/logger': 1.1.4
+ http-proxy-agent: 7.0.2
+ https-proxy-agent: 7.0.6
+ tslib: 2.8.1
+ transitivePeerDependencies:
+ - supports-color
+
+ '@azure/[email protected]':
+ dependencies:
+ tslib: 2.8.1
+
+ '@azure/[email protected]':
+ dependencies:
+ '@azure/abort-controller': 2.1.2
+ tslib: 2.8.1
+
+ '@azure/[email protected]':
+ dependencies:
+ fast-xml-parser: 5.2.1
+ tslib: 2.8.1
+
+ '@azure/[email protected]':
+ dependencies:
+ tslib: 2.8.1
+
+ '@azure/[email protected]':
+ dependencies:
+ '@azure/abort-controller': 2.1.2
+ '@azure/core-auth': 1.9.0
+ '@azure/core-client': 1.9.3
+ '@azure/core-http-compat': 2.2.0
+ '@azure/core-lro': 2.7.2
+ '@azure/core-paging': 1.6.2
+ '@azure/core-rest-pipeline': 1.19.1
+ '@azure/core-tracing': 1.2.0
+ '@azure/core-util': 1.11.0
+ '@azure/core-xml': 1.4.5
+ '@azure/logger': 1.1.4
+ events: 3.3.0
+ tslib: 2.8.1
+ transitivePeerDependencies:
+ - supports-color
+
dependencies:
'@babel/helper-validator-identifier': 7.25.9
@@ -11304,12 +11453,12 @@ snapshots:
- supports-color
- typescript
dependencies:
rehype-expressive-code: 0.41.2
dependencies:
'@astrojs/compiler': 2.11.0
'@astrojs/internal-helpers': 0.6.1
@@ -11360,7 +11509,7 @@ snapshots:
ultrahtml: 1.6.0
unifont: 0.2.0
unist-util-visit: 5.0.0
- unstorage: 1.15.0([email protected])
+ unstorage: 1.15.0(@azure/[email protected])([email protected])
vfile: 6.0.3
@@ -12866,6 +13015,10 @@ snapshots:
dependencies:
strnum: 1.1.2
+ dependencies:
+ strnum: 2.0.5
+
dependencies:
reusify: 1.0.4
@@ -15593,9 +15746,9 @@ snapshots:
dependencies:
'@types/picomatch': 3.0.2
github-slugger: 2.0.0
hast-util-from-html: 2.0.3
@@ -15609,9 +15762,9 @@ snapshots:
transitivePeerDependencies:
- supports-color
dependencies:
@@ -15683,6 +15836,8 @@ snapshots:
+
dependencies:
style-to-object: 1.0.8
@@ -16081,7 +16236,7 @@ snapshots:
'@unrs/resolver-binding-win32-ia32-msvc': 1.7.0
'@unrs/resolver-binding-win32-x64-msvc': 1.7.0
dependencies:
anymatch: 3.1.3
chokidar: 4.0.3
@@ -16092,6 +16247,7 @@ snapshots:
ofetch: 1.4.1
ufo: 1.5.4
optionalDependencies:
+ '@azure/storage-blob': 12.27.0
idb-keyval: 6.2.1