Skip to content

Commit

Permalink
feat: tus v1 stable
Browse files Browse the repository at this point in the history
  • Loading branch information
fenos committed Dec 7, 2023
1 parent b6385fa commit f84a4d6
Show file tree
Hide file tree
Showing 16 changed files with 2,133 additions and 1,499 deletions.
2,779 changes: 1,724 additions & 1,055 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
"@fastify/swagger": "^8.3.1",
"@fastify/swagger-ui": "^1.7.0",
"@isaacs/ttlcache": "^1.4.1",
"@tus/file-store": "^1.0.0-beta.1",
"@tus/s3-store": "https://gitpkg.now.sh/supabase/tus-node-server/packages/s3-store/dist?build",
"@tus/server": "https://gitpkg.now.sh/supabase/tus-node-server/packages/server/dist?build",
"@tus/file-store": "https://gitpkg.now.sh/supabase/tus-node-server/packages/file-store/dist?supabase/build-v2",
"@tus/s3-store": "https://gitpkg.now.sh/supabase/tus-node-server/packages/s3-store/dist?supabase/build-v2",
"@tus/server": "https://gitpkg.now.sh/supabase/tus-node-server/packages/server/dist?supabase/build-v2",
"agentkeepalive": "^4.2.1",
"async-retry": "^1.3.3",
"axios": "^0.27.2",
Expand All @@ -46,7 +46,6 @@
"crypto-js": "^4.2.0",
"dotenv": "^16.0.0",
"fastify": "^4.8.1",
"fastify-cors": "^6.1.0",
"fastify-metrics": "^10.2.0",
"fastify-plugin": "^4.0.0",
"fs-extra": "^10.0.1",
Expand Down
7 changes: 7 additions & 0 deletions src/database/pubsub.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { PostgresPubSub } from '../pubsub'
import { getConfig } from '../config'

const { isMultitenant, databaseURL, multitenantDatabaseUrl } = getConfig()

const connectionString = isMultitenant ? (multitenantDatabaseUrl as string) : databaseURL
export const PubSub = new PostgresPubSub(connectionString)
17 changes: 6 additions & 11 deletions src/database/tenant.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import createSubscriber from 'pg-listen'
import { getConfig } from '../config'
import { decrypt, verifyJWT } from '../auth'
import { runMigrationsOnTenant } from './migrate'
import { knex } from './multitenant-db'
import { StorageBackendError } from '../storage'
import { JwtPayload } from 'jsonwebtoken'
import { PubSubAdapter } from '../pubsub'

interface TenantConfig {
anonKey: string
Expand Down Expand Up @@ -197,19 +197,14 @@ const TENANTS_UPDATE_CHANNEL = 'tenants_update'
/**
* Keeps the in memory config cache up to date
*/
export async function listenForTenantUpdate(): Promise<void> {
const subscriber = createSubscriber({ connectionString: multitenantDatabaseUrl })

subscriber.notifications.on(TENANTS_UPDATE_CHANNEL, (tenantId) => {
export async function listenForTenantUpdate(pubSub: PubSubAdapter): Promise<void> {
await pubSub.subscribe(TENANTS_UPDATE_CHANNEL, (tenantId) => {
tenantConfigCache.delete(tenantId)
})

subscriber.events.on('error', (error) => {
console.error('Postgres notification subscription error:', error)
})

await subscriber.connect()
await subscriber.listenTo(TENANTS_UPDATE_CHANNEL)
// subscriber.events.on('error', (error) => {
// console.error('Postgres notification subscription error:', error)
// })
}

async function cacheTenantConfigAndRunMigrations(
Expand Down
12 changes: 3 additions & 9 deletions src/http/routes/tus/file-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@ import { Upload } from '@tus/server'
import fsExtra from 'fs-extra'
import path from 'path'
import { FileBackend } from '../../../storage/backend'

type Store = {
get(key: string): Upload | undefined
set(key: string, value: Upload): void
delete(key: string): void
all: Record<string, Upload>
}
import { Configstore } from '@tus/file-store/configstores'

type FileStoreOptions = {
directory: string
configstore?: Store
configstore?: Configstore
expirationPeriodInMilliseconds?: number
}

Expand All @@ -33,7 +27,7 @@ export class FileStore extends TusFileStore {
cacheControl: file.metadata?.cacheControl || '',
contentType: file.metadata?.contentType || '',
})
this.configstore.set(file.id, file)
await this.configstore.set(file.id, file)
return file
}
}
290 changes: 0 additions & 290 deletions src/http/routes/tus/handlers.ts

This file was deleted.

Loading

0 comments on commit f84a4d6

Please sign in to comment.