@stacksjs/storage 0.74.20 → 0.74.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/uploaded-file.js +1 -1
- package/package.json +10 -10
package/dist/uploaded-file.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{basename,extname,join}from"node:path";
|
|
1
|
+
import{basename,extname,join}from"node:path";export class UploadedFile{_file;_hashName=null;constructor(file){this._file=file}get name(){return this._file.name}get extension(){return extname(this._file.name).slice(1).toLowerCase()}get mimeType(){return this._file.type}get size(){return this._file.size}get file(){return this._file}hashName(extension){if(!this._hashName){const hash=crypto.randomUUID().replace(/-/g,"").slice(0,32),ext=extension||this.extension;this._hashName=ext?`${hash}.${ext}`:hash}return this._hashName}async arrayBuffer(){return this._file.arrayBuffer()}async bytes(){const buffer=await this._file.arrayBuffer();return new Uint8Array(buffer)}async text(){return this._file.text()}isValid(){return this._file.size>0}async store(path="",disk="local"){const filename=this.hashName(),fullPath=path?join(path,filename):filename,contents=await this.bytes(),{Storage}=await import("./facade");await Storage.disk(disk).write(fullPath,contents);return fullPath}async storeAs(path,name,disk="local"){if(name.includes("..")||name.includes("/")||name.includes("\\"))throw Error("Invalid filename: path traversal or directory separator detected");const sanitizedName=basename(name),fullPath=path?join(path,sanitizedName):sanitizedName,contents=await this.bytes(),{Storage}=await import("./facade");await Storage.disk(disk).write(fullPath,contents);return fullPath}async storePublicly(path=""){return this.store(path,"public")}async storePubliclyAs(path,name){return this.storeAs(path,name,"public")}async move(path,disk="local"){const contents=await this.bytes(),{Storage}=await import("./facade");await Storage.disk(disk).write(path,contents);return path}getClientOriginalName(){return basename(this._file.name,extname(this._file.name))}getClientOriginalExtension(){return this.extension}getClientMimeType(){return this._file.type}getSize(){const bytes=this._file.size;if(bytes<1024)return`${bytes} B`;if(bytes<1048576)return`${(bytes/1024).toFixed(2)} KB`;if(bytes<1073741824)return`${(bytes/1048576).toFixed(2)} MB`;return`${(bytes/1073741824).toFixed(2)} GB`}isOneOf(mimeTypes){return mimeTypes.some((type)=>{if(type.endsWith("/*")){const category=type.slice(0,-2);return this._file.type.startsWith(category)}return this._file.type===type})}isImage(){return this._file.type.startsWith("image/")}isVideo(){return this._file.type.startsWith("video/")}isAudio(){return this._file.type.startsWith("audio/")}isPdf(){return this._file.type==="application/pdf"}}export function uploadedFile(file){return new UploadedFile(file)}export function uploadedFiles(files){return files.map((f)=>new UploadedFile(f))}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@stacksjs/storage",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "0.74.
|
|
5
|
+
"version": "0.74.22",
|
|
6
6
|
"description": "The Stacks file system.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"contributors": [
|
|
@@ -61,19 +61,19 @@
|
|
|
61
61
|
"prepublishOnly": "bun run build"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@stacksjs/arrays": "0.74.
|
|
65
|
-
"@stacksjs/cli": "0.74.
|
|
66
|
-
"@stacksjs/config": "0.74.
|
|
67
|
-
"@stacksjs/env": "0.74.
|
|
68
|
-
"@stacksjs/error-handling": "0.74.
|
|
69
|
-
"@stacksjs/logging": "0.74.
|
|
70
|
-
"@stacksjs/path": "0.74.
|
|
71
|
-
"@stacksjs/strings": "0.74.
|
|
64
|
+
"@stacksjs/arrays": "0.74.22",
|
|
65
|
+
"@stacksjs/cli": "0.74.22",
|
|
66
|
+
"@stacksjs/config": "0.74.22",
|
|
67
|
+
"@stacksjs/env": "0.74.22",
|
|
68
|
+
"@stacksjs/error-handling": "0.74.22",
|
|
69
|
+
"@stacksjs/logging": "0.74.22",
|
|
70
|
+
"@stacksjs/path": "0.74.22",
|
|
71
|
+
"@stacksjs/strings": "0.74.22",
|
|
72
72
|
"@stacksjs/ts-cloud": "^0.12.10",
|
|
73
73
|
"ts-images": "^0.2.11"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
|
-
"@stacksjs/types": "0.74.
|
|
76
|
+
"@stacksjs/types": "0.74.22",
|
|
77
77
|
"better-dx": "^0.2.24"
|
|
78
78
|
}
|
|
79
79
|
}
|