|
1 | 1 | import { EventEmitter } from "events"; |
2 | | -import http from 'http'; |
| 2 | +import * as fs from "fs"; |
| 3 | +import http from "http"; |
3 | 4 |
|
4 | 5 | /** |
5 | 6 | * arguments of constructor which in class extend DataStore |
6 | 7 | */ |
7 | | -declare interface DataStoreOptions{ |
| 8 | +declare interface DataStoreOptions { |
8 | 9 | path: string; |
9 | | - namingFunction?: (req : http.IncomingMessage) => string; |
| 10 | + namingFunction?: (req: http.IncomingMessage) => string; |
10 | 11 | relativeLocation?: string; |
11 | 12 | } |
12 | 13 |
|
13 | | -declare interface FileStoreOptions extends DataStoreOptions{ |
| 14 | +declare interface FileStoreOptions extends DataStoreOptions { |
14 | 15 | directory?: string; |
15 | 16 | } |
16 | 17 |
|
17 | | -declare interface GCStoreOptions extends DataStoreOptions{ |
| 18 | +declare interface GCStoreOptions extends DataStoreOptions { |
18 | 19 | bucket: string; |
19 | 20 | projectId: string; |
20 | 21 | keyFilename: string; |
21 | 22 | } |
22 | 23 |
|
23 | | -declare interface S3StoreOptions extends DataStoreOptions{ |
| 24 | +declare interface S3StoreOptions extends DataStoreOptions { |
24 | 25 | accessKeyId: string; |
25 | 26 | secretAccessKey: string; |
26 | 27 | bucket: string; |
27 | 28 | tmpDirPrefix: string; |
28 | 29 | partSize: number; |
29 | 30 | } |
30 | 31 |
|
31 | | -declare class File{ |
| 32 | +declare class File { |
32 | 33 | id: string; |
33 | 34 | upload_length: any; |
34 | 35 | upload_defer_length: any; |
35 | 36 | upload_metadata: any; |
36 | | - constructor(file_id: string, upload_length: any, upload_defer_length: any, upload_metadata: any); |
| 37 | + constructor( |
| 38 | + file_id: string, |
| 39 | + upload_length: any, |
| 40 | + upload_defer_length: any, |
| 41 | + upload_metadata: any |
| 42 | + ); |
37 | 43 | } |
38 | 44 |
|
39 | 45 | /** |
40 | 46 | * Based store for all DataStore classes. |
41 | 47 | */ |
42 | | -export declare class DataStore extends EventEmitter{ |
43 | | - constructor(options : DataStoreOptions); |
44 | | - get extensions() : any; |
45 | | - set extensions(extensions_array : any); |
46 | | - create(req: http.IncomingMessage): Promise<any>; |
47 | | - write(req: http.IncomingMessage, file_id?: string, offset?: number): Promise<any>; |
48 | | - getOffset(id: string): Promise<any>; |
| 48 | +export declare class DataStore extends EventEmitter { |
| 49 | + constructor(options: DataStoreOptions); |
| 50 | + get extensions(): any; |
| 51 | + set extensions(extensions_array: any); |
| 52 | + create(req: Partial<http.IncomingMessage>): Promise<any>; |
| 53 | + write( |
| 54 | + req: http.IncomingMessage, |
| 55 | + file_id?: string, |
| 56 | + offset?: number |
| 57 | + ): Promise<any>; |
| 58 | + getOffset(file_id: string): Promise<any>; |
49 | 59 | } |
50 | 60 |
|
51 | 61 | /** |
52 | 62 | * file store in local storage |
53 | 63 | */ |
54 | | -export declare class FileStore extends DataStore{ |
55 | | - constructor(options : FileStoreOptions); |
56 | | - create(req: http.IncomingMessage): Promise<any>; |
57 | | - write(req: http.IncomingMessage, file_id?: string, offset?: number): Promise<any>; |
58 | | - getOffset(file_id: string): Promise<any>; |
| 64 | +export declare class FileStore extends DataStore { |
| 65 | + constructor(options: FileStoreOptions); |
| 66 | + read(file_id: string): fs.ReadStream; |
| 67 | + getOffset(file_id: string): Promise<fs.Stats & File>; |
59 | 68 | } |
60 | 69 |
|
61 | 70 | /** |
62 | 71 | * file store in Google Cloud |
63 | 72 | */ |
64 | | -export declare class GCSDataStore extends DataStore{ |
| 73 | +export declare class GCSDataStore extends DataStore { |
65 | 74 | constructor(options: GCStoreOptions); |
66 | | - create(req: http.IncomingMessage): Promise<any>; |
67 | | - write(req: http.IncomingMessage, file_id?: string, offset?: number): Promise<any>; |
68 | | - getOffset(file_id: string): Promise<any>; |
69 | 75 | } |
70 | 76 |
|
71 | 77 | /** |
72 | 78 | * file store in AWS S3 |
73 | 79 | */ |
74 | 80 | export declare class S3Store extends DataStore { |
75 | | - constructor(options : S3StoreOptions); |
76 | | - create(req: http.IncomingMessage): Promise<any>; |
77 | | - write(req: http.IncomingMessage, file_id?: string, offset?: number): Promise<any>; |
78 | | - getOffset(file_id: string, with_parts?: boolean): Promise<any>; |
| 81 | + constructor(options: S3StoreOptions); |
| 82 | + getOffset(file_id: string, with_parts?: boolean): Promise<any>; |
79 | 83 | } |
80 | 84 |
|
81 | 85 | /** |
82 | 86 | * Tus protocol server implements |
83 | 87 | */ |
84 | | -export declare class Server extends EventEmitter{ |
| 88 | +export declare class Server extends EventEmitter { |
85 | 89 | constructor(); |
86 | | - get datastore() : DataStore; |
| 90 | + get datastore(): DataStore; |
87 | 91 | set datastore(store: DataStore); |
88 | | - get(path: string, callback: Function): any; |
89 | | - handle(req: http.IncomingMessage, res: http.ServerResponse): http.ServerResponse; |
| 92 | + get(path: string, callback: (...args) => any): any; |
| 93 | + handle( |
| 94 | + req: http.IncomingMessage, |
| 95 | + res: http.ServerResponse |
| 96 | + ): http.ServerResponse; |
90 | 97 | listen(): http.Server; |
91 | 98 | } |
92 | 99 |
|
@@ -130,3 +137,8 @@ export declare const ERRORS: { |
130 | 137 | body: string; |
131 | 138 | }; |
132 | 139 | }; |
| 140 | + |
| 141 | +export declare class Metadata { |
| 142 | + static parse(str: string): Record<string, string>; |
| 143 | + static stringify(metadata: Record<string, string>): string; |
| 144 | +} |
0 commit comments