This repository was archived by the owner on Feb 4, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 7 files changed +18
-13
lines changed Expand file tree Collapse file tree 7 files changed +18
-13
lines changed Original file line number Diff line number Diff line change 1
1
import { responses } from '../../../responses'
2
2
import perms from '../../../util/perms'
3
- import { get as getUploadProvider } from '../../../uploads'
3
+ import { upload } from '../../../uploads'
4
4
import toBuffer from 'data-uri-to-buffer'
5
5
6
6
const itemSchema = {
@@ -35,7 +35,6 @@ export default {
35
35
} ,
36
36
bodyLimit : 2 ** 30 , // 1 GiB
37
37
handler : async ( { req } ) => {
38
- const uploadProvider = getUploadProvider ( )
39
38
let convertedFiles
40
39
try {
41
40
convertedFiles = req . body . files . map ( ( { name, data } ) => {
@@ -51,7 +50,7 @@ export default {
51
50
try {
52
51
const files = await Promise . all (
53
52
convertedFiles . map ( async ( { name, data } ) => {
54
- const url = await uploadProvider . upload ( data , name )
53
+ const url = await upload ( data , name )
55
54
56
55
return {
57
56
name,
Original file line number Diff line number Diff line change 1
1
import { responses } from '../../../responses'
2
2
import perms from '../../../util/perms'
3
- import { get as getUploadProvider } from '../../../uploads'
3
+ import { getUrl } from '../../../uploads'
4
4
5
5
export default {
6
6
method : 'POST' ,
@@ -31,11 +31,9 @@ export default {
31
31
}
32
32
} ,
33
33
handler : async ( { req } ) => {
34
- const uploadProvider = getUploadProvider ( )
35
-
36
34
const data = await Promise . all (
37
35
req . body . uploads . map ( async ( { sha256, name } ) => {
38
- const url = await uploadProvider . getUrl ( sha256 , name )
36
+ const url = await getUrl ( sha256 , name )
39
37
40
38
return {
41
39
sha256,
Original file line number Diff line number Diff line change 1
- import { Provider } from '../../../uploads/types '
1
+ import { Provider } from '../../../uploads/provider '
2
2
3
3
export default class DummyProvider implements Provider {
4
4
upload = async ( ) : Promise < string > => ''
Original file line number Diff line number Diff line change 1
1
import { Storage , Bucket , File } from '@google-cloud/storage'
2
2
import crypto from 'crypto'
3
- import { Provider } from '../../../uploads/types '
3
+ import { Provider } from '../../../uploads/provider '
4
4
5
5
interface GcsProviderOptions {
6
6
credentials : Record < string , unknown > ;
Original file line number Diff line number Diff line change 1
- import { Provider } from '../../../uploads/types '
1
+ import { Provider } from '../../../uploads/provider '
2
2
import process from 'process'
3
3
import path from 'path'
4
4
import fs from 'fs'
Original file line number Diff line number Diff line change 1
1
import config from '../config/server'
2
2
import path from 'path'
3
- import { Provider , ProviderConstructor } from './types '
3
+ import { Provider , ProviderConstructor } from './provider '
4
4
import { FastifyInstance } from 'fastify'
5
5
6
6
let provider : Provider | null = null
@@ -15,10 +15,18 @@ export const init = (app: FastifyInstance | null): void => {
15
15
provider = new ProviderClass ( config . uploadProvider . options ?? { } , app )
16
16
}
17
17
18
- export const get = ( ) : Provider => {
18
+ export const upload = ( data : Buffer , name : string ) : Promise < string > => {
19
19
if ( provider === null ) {
20
20
throw new Error ( 'upload provider called before initialization' )
21
21
}
22
22
23
- return provider
23
+ return provider . upload ( data , name )
24
+ }
25
+
26
+ export const getUrl = ( sha256 : string , name : string ) : Promise < string | null > => {
27
+ if ( provider === null ) {
28
+ throw new Error ( 'upload provider called before initialization' )
29
+ }
30
+
31
+ return provider . getUrl ( sha256 , name )
24
32
}
File renamed without changes.
You can’t perform that action at this time.
0 commit comments