@odvi/create-dtt-framework 0.1.16 → 0.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/template/package.json
CHANGED
|
@@ -40,6 +40,9 @@ const envSchema = z.object({
|
|
|
40
40
|
SYNOLOGY_HOST: z.string().url().optional(),
|
|
41
41
|
SYNOLOGY_USERNAME: z.string().optional(),
|
|
42
42
|
SYNOLOGY_PASSWORD: z.string().optional(),
|
|
43
|
+
|
|
44
|
+
// UploadThing (optional)
|
|
45
|
+
UPLOADTHING_TOKEN: z.string().optional(),
|
|
43
46
|
})
|
|
44
47
|
|
|
45
48
|
export const env = envSchema.parse(process.env)
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { UTApi } from 'uploadthing/server'
|
|
2
|
+
import { env } from '@/config/env'
|
|
3
|
+
|
|
4
|
+
export class UploadThingClient {
|
|
5
|
+
private api: UTApi | null = null
|
|
6
|
+
|
|
7
|
+
constructor() {
|
|
8
|
+
// UTApi automatically reads UPLOADTHING_TOKEN from environment
|
|
9
|
+
// Only initialize if token is configured
|
|
10
|
+
if (env.UPLOADTHING_TOKEN) {
|
|
11
|
+
this.api = new UTApi()
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Check if the client is configured
|
|
17
|
+
*/
|
|
18
|
+
isConfigured(): boolean {
|
|
19
|
+
return this.api !== null
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Get the underlying UTApi instance
|
|
24
|
+
*/
|
|
25
|
+
getApi(): UTApi {
|
|
26
|
+
if (!this.api) {
|
|
27
|
+
throw new Error('UploadThing is not configured. Set UPLOADTHING_TOKEN environment variable.')
|
|
28
|
+
}
|
|
29
|
+
return this.api
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* List files from UploadThing
|
|
34
|
+
*/
|
|
35
|
+
async listFiles(options?: { limit?: number; offset?: number }) {
|
|
36
|
+
const api = this.getApi()
|
|
37
|
+
return api.listFiles(options)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Delete a file by its key
|
|
42
|
+
*/
|
|
43
|
+
async deleteFile(fileKey: string) {
|
|
44
|
+
const api = this.getApi()
|
|
45
|
+
return api.deleteFiles(fileKey)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Delete multiple files by their keys
|
|
50
|
+
*/
|
|
51
|
+
async deleteFiles(fileKeys: string[]) {
|
|
52
|
+
const api = this.getApi()
|
|
53
|
+
return api.deleteFiles(fileKeys)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Get file URLs by their keys
|
|
58
|
+
*/
|
|
59
|
+
async getFileUrls(fileKeys: string[]) {
|
|
60
|
+
const api = this.getApi()
|
|
61
|
+
return api.getFileUrls(fileKeys)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Rename a file
|
|
66
|
+
*/
|
|
67
|
+
async renameFile(fileKey: string, newName: string) {
|
|
68
|
+
const api = this.getApi()
|
|
69
|
+
return api.renameFiles({ [fileKey]: newName })
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Rename multiple files
|
|
74
|
+
*/
|
|
75
|
+
async renameFiles(updates: Record<string, string>) {
|
|
76
|
+
const api = this.getApi()
|
|
77
|
+
return api.renameFiles(updates)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Get usage info for the app
|
|
82
|
+
*/
|
|
83
|
+
async getUsageInfo() {
|
|
84
|
+
const api = this.getApi()
|
|
85
|
+
return api.getUsageInfo()
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export const uploadThingClient = new UploadThingClient()
|