@isoftdata/file-service
Advanced tools
@@ -19,4 +19,4 @@ import { UploadResult } from '../app/types.js'; | ||
| addFile: (opts: FileOpts) => string; | ||
| upload: () => Promise<UploadResult[]>; | ||
| filesToBeUploaded: FileOpts[]; | ||
| upload: () => Promise<Array<UploadResult>>; | ||
| filesToBeUploaded: Array<FileOpts>; | ||
| } |
| import FormData from 'form-data'; | ||
| import axios from 'axios'; | ||
| import { Readable } from 'stream'; | ||
| import { randomUUID } from 'crypto'; | ||
| import { pipeline, withHttpError, withJsonResponse } from 'fetch-extras'; | ||
| const fetchWithExtras = pipeline(fetch, withHttpError(), withJsonResponse()); | ||
| export class FileServiceClient { | ||
@@ -26,9 +27,8 @@ constructor(opts) { | ||
| }); | ||
| const config = { | ||
| method: 'post', | ||
| url: `${this.url}/upload`, | ||
| return fetchWithExtras(`${this.url}/upload`, { | ||
| method: 'POST', | ||
| headers: data.getHeaders(), | ||
| data, | ||
| }; | ||
| return (await axios.request(config)).data; | ||
| body: Readable.toWeb(data), //idk why Readable.toWeb is ReadableStream<any> instead of ReadableStream<Uint8Array>, but it is, so we have to cast it to the correct type | ||
| duplex: 'half', // This must be passed when the body is a ReadableStream. `duplex` isn't in the types yet, so we have to cast the options to `RequestInit` to avoid a type error. Docs for duplex: https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#duplex | ||
| }); | ||
| }; | ||
@@ -35,0 +35,0 @@ this.filesToBeUploaded = []; |
+2
-2
| { | ||
| "name": "@isoftdata/file-service", | ||
| "version": "7.0.0", | ||
| "version": "7.0.1-beta.0", | ||
| "description": "A generic files service for any ISoft platform.", | ||
@@ -40,6 +40,6 @@ "type": "module", | ||
| "dependencies": { | ||
| "axios": "^1.13.2", | ||
| "debug": "^4.4.3", | ||
| "express": "^4.22.1", | ||
| "express-fileupload": "^1.5.2", | ||
| "fetch-extras": "^3.0.0", | ||
| "form-data": "^4.0.5", | ||
@@ -46,0 +46,0 @@ "md5": "^2.3.0", |
+1
-1
@@ -174,3 +174,3 @@ # Project Background | ||
| Supports/requires/uses Node 20 and therefore Ubuntu 20 or higher on the host OS. | ||
| Supports/requires/uses Node 20 in Docker builds and therefore requires Ubuntu 20 or higher on the host OS. | ||
@@ -177,0 +177,0 @@ ## Version 7 |
Network access
Supply chain riskThis module accesses the network.
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
40488
1.37%3
50%1
Infinity%+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed