Skip to content

Commit b06bf91

Browse files
committed
Refactor index.js to use ES modules and improve error handling for file uploads
1 parent 9deee64 commit b06bf91

1 file changed

Lines changed: 19 additions & 22 deletions

File tree

src/index.js

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
1-
const core = require('@actions/core');
2-
const axios = require('axios');
1+
import * as core from '@actions/core';
2+
import fs from 'fs';
3+
import { put } from '@vercel/blob';
34

45
async function run() {
5-
try {
6-
const sourcePath = core.getInput('source');
7-
const destinationPath = core.getInput('destination');
6+
try {
7+
const sourcePath = core.getInput('source', { required: true });
8+
const destinationPath = core.getInput('destination', { required: true });
9+
const token = core.getInput('vercelToken', { required: true });
810

9-
if (!sourcePath || !destinationPath) {
10-
throw new Error('Both source and destination paths are required.');
11-
}
12-
13-
// Here you would add the logic to interact with the Vercel Blob API
14-
// For example, uploading a file from sourcePath to destinationPath
11+
if (!fs.existsSync(sourcePath)) {
12+
throw new Error(`Source file does not exist: ${sourcePath}`);
13+
}
1514

16-
core.info(`Source Path: ${sourcePath}`);
17-
core.info(`Destination Path: ${destinationPath}`);
15+
const fileStream = fs.createReadStream(sourcePath);
1816

19-
// Simulate API interaction
20-
const response = await axios.post('https://api.vercel.com/v1/blob', {
21-
source: sourcePath,
22-
destination: destinationPath
23-
});
17+
const result = await put(destinationPath, fileStream, {
18+
token,
19+
});
2420

25-
core.setOutput('response', response.data);
26-
} catch (error) {
27-
core.setFailed(error.message);
28-
}
21+
core.info(`File uploaded to ${result.url}`);
22+
core.setOutput('url', result.url);
23+
} catch (error) {
24+
core.setFailed(error.message);
25+
}
2926
}
3027

3128
run();

0 commit comments

Comments
 (0)