Skip to content

Commit a378a22

Browse files
authored
feat: allow provided file paths to be URLs (#31)
2 parents 3213673 + d6e2755 commit a378a22

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,20 @@ const fileTypesMap: Record<string, string> = {
6262

6363
const files = await Promise.all(filePaths.map(async filePath => {
6464
const type = fileTypesMap[path.extname(filePath)];
65+
// Check if the path is an url
66+
if (/^https?:\/\//.test(filePath)) {
67+
const url = new URL(filePath);
68+
const res = await fetch(url);
69+
const data = await res.blob();
70+
71+
return new File([data], path.basename(url.pathname), {type: data.type});
72+
}
73+
6574
const data = await fs.readFile(filePath);
6675
return new File([data], path.basename(filePath), {type});
6776
}));
6877

69-
// If primary file is specified, check that it is present
78+
// If a primary file is specified, check that it is present
7079
if (primaryFileName !== null && !files.some(f => f.name === primaryFileName)) {
7180
core.setFailed(new Error(`Primary file “${primaryFileName}” is not present in the list of files.`));
7281
process.exit(1);

0 commit comments

Comments
 (0)