Skip to content

Commit

Permalink
fix upload logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ayeressian committed Jun 25, 2020
1 parent a708c33 commit ef0a7d3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9744,7 +9744,7 @@ function uploadFile(entry, storageName, accessKey) {
}
async function run(path, storageName, accessKey) {
for await (const entry of readdirp_1.default(path)) {
uploadFile(entry, storageName, accessKey);
await uploadFile(entry, storageName, accessKey);
}
}
exports.default = run;
Expand Down
18 changes: 11 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ import { getInput, setFailed } from '@actions/core';
import { join } from 'path';
import { Utils } from '@technote-space/github-action-helper';

try {
const source = join(Utils.getWorkspace(), getInput('source'));
const storageZoneName = getInput('storageZoneName');
const accessKey = getInput('accessKey');
uploader(source, storageZoneName, accessKey);
} catch (error) {
setFailed(error.message);
async function run() {
try {
const source = join(Utils.getWorkspace(), getInput('source'));
const storageZoneName = getInput('storageZoneName');
const accessKey = getInput('accessKey');
await uploader(source, storageZoneName, accessKey);
} catch (error) {
setFailed(error.message);
}
}

run();
6 changes: 4 additions & 2 deletions src/uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function uploadFile(entry: readdirp.EntryInfo, storageName: string, accessKey: s
const fileSizeInBytes = stats.size;

let readStream = fs.createReadStream(entry.fullPath);

console.log(entry);
return fetch(`https://storage.bunnycdn.com/${storageName}/${entry.path}`, {
method: 'POST',
headers: {
Expand All @@ -19,7 +19,9 @@ function uploadFile(entry: readdirp.EntryInfo, storageName: string, accessKey: s
}

export default async function run(path: string, storageName: string, accessKey: string) {
const uploadPromises = [];
for await (const entry of readdirp(path)) {
uploadFile(entry, storageName, accessKey);
uploadPromises.push(uploadFile(entry, storageName, accessKey));
}
await Promise.all(uploadPromises);
}

0 comments on commit ef0a7d3

Please sign in to comment.