Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add @tus/azure-store #645

Merged
merged 12 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/rude-geckos-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tus/azure-store": minor
---

Add basic store for Azure
4 changes: 3 additions & 1 deletion demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
"scripts": {
"start": "node server.js",
"start:gcs": "cross-env DATA_STORE=GCSDataStore node server.js",
"start:s3": "cross-env DATA_STORE=S3Store node server.js"
"start:s3": "cross-env DATA_STORE=S3Store node server.js",
"start:azure": "cross-env DATA_STORE=AzureBlobStore node server.js"
},
"dependencies": {
"@tus/file-store": "^1.5.0",
"@tus/gcs-store": "^1.4.0",
"@tus/s3-store": "^1.6.0",
"@tus/azure-store": "^0.0.0",
"@tus/server": "^1.8.0",
"tus-js-client": "^2.3.2"
},
Expand Down
44 changes: 34 additions & 10 deletions demo/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ const path = require('path')
const fs = require('fs')
const assert = require('assert')

const {Server, EVENTS} = require('@tus/server')
const {GCSDataStore} = require('@tus/gcs-store')
const {S3Store} = require('@tus/s3-store')
const {FileStore} = require('@tus/file-store')
const { Server, EVENTS } = require('@tus/server')
const { GCSDataStore } = require('@tus/gcs-store')
const { S3Store } = require('@tus/s3-store')
const { FileStore } = require('@tus/file-store')
const { AzureStore } = require('@tus/azure-store')

const stores = {
GCSDataStore: () =>
Expand Down Expand Up @@ -36,11 +37,34 @@ const stores = {
},
})
},
FileStore: () => new FileStore({directory: './files'}),
FileStore: () => new FileStore({ directory: './files' }),

AzureBlobStore: () => {
assert.ok(
process.env.AZURE_ACCOUNT_ID,
'environment variable `AZURE_ACCOUNT_ID` must be set'
)

assert.ok(
process.env.AZURE_ACCOUNT_KEY,
'environment variable `AZURE_ACCOUNT_KEY` must be set'
)

assert.ok(
process.env.AZURE_CONTAINER_NAME,
'environment variable `AZURE_CONTAINER_NAME` must be set'
)

return new AzureStore({
account: process.env.AZURE_ACCOUNT_ID,
accountKey: process.env.AZURE_ACCOUNT_KEY,
containerName: process.env.AZURE_CONTAINER_NAME,
})
}
}
const storeName = process.env.DATA_STORE || 'FileStore'
const store = stores[storeName]
const server = new Server({path: '/files', datastore: store()})
const server = new Server({ path: '/files', datastore: store() })

/**
* Basic GET handler to serve the demo html/js
Expand All @@ -60,7 +84,8 @@ const writeFile = (req, res) => {
filename = path.join(process.cwd(), '../node_modules/tus-js-client', filename)
fs.readFile(filename, 'binary', (err, file) => {
if (err) {
res.writeHead(500, {'Content-Type': 'text/plain'})
res.writeHead(500, { 'Content-Type': 'text/plain' })
console.log(err);
res.write(err)
res.end()
return
Expand Down Expand Up @@ -92,8 +117,7 @@ server.get('/dist/tus.min.js.map', writeFile)

server.on(EVENTS.EVENT_UPLOAD_COMPLETE, (event) => {
console.log(
`[${new Date().toLocaleTimeString()}] [EVENT HOOK] Upload complete for file ${
event.file.id
`[${new Date().toLocaleTimeString()}] [EVENT HOOK] Upload complete for file ${event.file.id
}`
)
})
Expand All @@ -108,7 +132,7 @@ server.on(EVENTS.EVENT_UPLOAD_COMPLETE, (event) => {

const host = '127.0.0.1'
const port = 1080
server.listen({host, port}, () => {
server.listen({ host, port }, () => {
console.log(
`[${new Date().toLocaleTimeString()}] tus server listening at http://${host}:${port} using ${storeName}`
)
Expand Down
Loading
Loading