forked from dharijanto/multer-proxy-storage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First go at getting savefiles.org upload to work
- Loading branch information
1 parent
8724aa7
commit b0a6377
Showing
8 changed files
with
107 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: Publish Package to npmjs | ||
on: | ||
push: | ||
branches: | ||
- master | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
# Setup .npmrc file to publish to npm | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: '20.x' | ||
registry-url: 'https://registry.npmjs.org' | ||
- run: npm ci | ||
- run: npm publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
node_modules/ | ||
package-lock.json | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
var multerProxyStorage = require('./lib/multer-proxy-storage.js') | ||
|
||
module.exports = multerProxyStorage | ||
exports.MulterSaveFilesOrgStorage = require('./lib/multer-savefilesorg-storage.js') |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
var axios = require('axios') | ||
var concat = require('concat-stream') | ||
var FormData = require('form-data') | ||
|
||
// Maximum time to upload to the server | ||
const UPLOAD_TIMEOUT = 5000 | ||
|
||
/* | ||
This is a custom multer storage engine that orxy the received data into a savefiles.org drive. | ||
The data is forwarded as multipart/form-data. | ||
opts: { | ||
serverPath: 'https://savefiles.org/api/v1/uploads', | ||
apiAccessToken: '<create access token under account settings>', | ||
fileParamName: 'file' // If left blank, this defaults to 'file', | ||
relativePath: '/' // If left blank, this defaults to root of drive '/', | ||
} | ||
SaveFilesOrg is expected to return: | ||
HTTP Code 201 | ||
or | ||
HTTP Code Non-201, which is considered an error | ||
*/ | ||
class MulterSaveFilesOrgStorage { | ||
constructor(opts) { | ||
this.opts = opts | ||
} | ||
|
||
_handleFile(req, file, cb) { | ||
var form = new FormData() | ||
// Use filepath to specify the file's fullpath. If we use filename, it'll be cut down into only the filename | ||
form.append(this.opts.fileParamName || 'file', file.stream, { filepath: file.originalname }) | ||
form.append('relativePath', this.opts.relativePath || '/') | ||
form.pipe(concat({ encoding: 'buffer' }, data => { | ||
axios.post( | ||
this.opts.serverPath, | ||
data, | ||
{ | ||
headers: { | ||
...form.getHeaders(), | ||
Authorization: `Bearer ${this.opts.apiAccessToken}` | ||
}, | ||
timeout: UPLOAD_TIMEOUT | ||
} | ||
).then(resp => { | ||
req.serverResp = resp.data | ||
cb(null) | ||
}).catch(err => { | ||
cb(err) | ||
}) | ||
})) | ||
} | ||
|
||
_removeFile(req, file, cb) { | ||
cb(null) | ||
} | ||
} | ||
|
||
module.exports = opts => { | ||
return new MulterSaveFilesOrgStorage(opts) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
{ | ||
"name": "multer-proxy-storage", | ||
"version": "1.0.2", | ||
"description": "Forward multipart/form-data file upload into a specified server.", | ||
"name": "multer-savefilesorg-storage", | ||
"version": "1.0.0", | ||
"description": "Forward multipart/form-data file upload into a savefiles.org drive.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": { | ||
"name": "Denny Harijanto", | ||
"email": "denny@nusantara-cloud.com", | ||
"url": "http://www.nusantara-cloud.com" | ||
"name": "Michael Hammond", | ||
"email": "mickeymond@gmail.com", | ||
"url": "https://mickeymond.xyz" | ||
}, | ||
"homepage": "https://github.com/nusantara-cloud/multer-proxy-storage", | ||
"homepage": "https://github.com/mickeymond/multer-savefilesorg-storage", | ||
"repository": { | ||
"bugs": { | ||
"url": "https://github.com/nusantara-cloud/multer-proxy-storage" | ||
"url": "https://github.com/mickeymond/multer-savefilesorg-storage/issues" | ||
}, | ||
"type": "git", | ||
"url": "git://github.com/nusantara-cloud/multer-proxy-storage.git" | ||
"url": "git://github.com/mickeymond/multer-savefilesorg-storage.git" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"axios": "^0.18.0", | ||
"concat-stream": "^1.6.2", | ||
"form-data": "^2.3.2" | ||
"axios": "^1.6.8", | ||
"concat-stream": "^2.0.0", | ||
"form-data": "^4.0.0" | ||
} | ||
} | ||
} |