@isoftdata/file-service
Advanced tools
@@ -19,4 +19,4 @@ import { UploadResult } from '../app/types.js'; | ||
| addFile: (opts: FileOpts) => string; | ||
| upload: () => Promise<Array<UploadResult>>; | ||
| filesToBeUploaded: Array<FileOpts>; | ||
| upload: () => Promise<UploadResult[]>; | ||
| filesToBeUploaded: 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 { | ||
@@ -27,8 +26,9 @@ constructor(opts) { | ||
| }); | ||
| return fetchWithExtras(`${this.url}/upload`, { | ||
| method: 'POST', | ||
| const config = { | ||
| method: 'post', | ||
| url: `${this.url}/upload`, | ||
| headers: data.getHeaders(), | ||
| 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 | ||
| }); | ||
| data, | ||
| }; | ||
| return (await axios.request(config)).data; | ||
| }; | ||
@@ -35,0 +35,0 @@ this.filesToBeUploaded = []; |
+6
-3
| { | ||
| "name": "@isoftdata/file-service", | ||
| "version": "7.0.1-beta.0", | ||
| "version": "7.0.1", | ||
| "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", | ||
@@ -80,3 +80,6 @@ "md5": "^2.3.0", | ||
| }, | ||
| "prettier": "@isoftdata/prettier-config" | ||
| "prettier": "@isoftdata/prettier-config", | ||
| "overrides": { | ||
| "qs": ">=6.15.2" | ||
| } | ||
| } |
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.
2
-33.33%0
-100%40005
-1.19%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed