FIXS
This commit is contained in:
		
							parent
							
								
									7b84ef1aa0
								
							
						
					
					
						commit
						1a62f1dd8e
					
				
							
								
								
									
										3
									
								
								.env.example
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								.env.example
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,3 @@ | |||||||
|  | STORAGE_LOCATION=files/ | ||||||
|  | STORAGE_PROVIDER=file | ||||||
|  | PORT=3003 | ||||||
| @ -4,27 +4,27 @@ import { join } from "path"; | |||||||
| import "missing-native-js-functions"; | import "missing-native-js-functions"; | ||||||
| 
 | 
 | ||||||
| export class FileStorage implements Storage { | export class FileStorage implements Storage { | ||||||
|   async get(path: string): Promise<Buffer | null> { | 	async get(path: string): Promise<Buffer | null> { | ||||||
|     path = join(process.env.STORAGE_LOCATION || "", path); | 		path = join(process.env.STORAGE_LOCATION || "", path); | ||||||
|     try { | 		try { | ||||||
|       const file = await fs.readFile(path); | 			const file = await fs.readFile(path); | ||||||
|       // @ts-ignore
 | 			// @ts-ignore
 | ||||||
|       return file; | 			return file; | ||||||
|     } catch (error) { | 		} catch (error) { | ||||||
|       return null; | 			return null; | ||||||
|     } | 		} | ||||||
|   } | 	} | ||||||
| 
 | 
 | ||||||
|   async set(path: string, value: any) { | 	async set(path: string, value: any) { | ||||||
|     path = join(process.env.STORAGE_LOCATION || "", path).replace(/[\\]/g, "/"); | 		path = join(process.env.STORAGE_LOCATION || "", path).replace(/[\\]/g, "/"); | ||||||
|     const dir = path.split("/").slice(0, -1).join("/"); |     	const dir = path.split("/").slice(0, -1).join("/"); | ||||||
|     await fs.mkdir(dir, { recursive: true }).caught(); |     	await fs.mkdir(dir, { recursive: true }).caught(); | ||||||
| 
 | 
 | ||||||
|     return fs.writeFile(path, value, { encoding: "binary" }); |     	return fs.writeFile(path, value, { encoding: "binary" }); | ||||||
|   } | 	} | ||||||
| 
 | 
 | ||||||
|   async delete(path: string) { | 	async delete(path: string) { | ||||||
|     path = join(process.env.STORAGE_LOCATION || "", path); | 		path = join(process.env.STORAGE_LOCATION || "", path); | ||||||
|     await fs.unlink(path); | 		await fs.unlink(path); | ||||||
|   } | 	} | ||||||
| } | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Joaquim Peixoto
						Joaquim Peixoto