Commit 78af8e45 authored by Ahmad's avatar Ahmad

Initial commit

parents
Pipeline #227 canceled with stages
const fs = require('fs');
const path = require('path');
const os = require('os');
// Reads and validates the DigitalOcean API token from Downloads
function readDigitalOceanToken() {
return new Promise((resolve, reject) => {
const downloadsDir = path.join(os.homedir(), 'Downloads');
const tokenFilePath = path.join(downloadsDir, 'do_api_token.txt');
if (!fs.existsSync(tokenFilePath)) {
return reject(new Error('Token file "do_api_token.txt" not found in Downloads folder.'));
}
fs.readFile(tokenFilePath, 'utf8', (err, data) => {
if (err) {
return reject(new Error(`Failed to read token file: ${err.message}`));
}
const token = data.trim();
const tokenRegex = /^[a-z0-9]{60,70}$/i;
if (!token) {
return reject(new Error('Token file is empty.'));
}
if (!tokenRegex.test(token)) {
return reject(new Error('Invalid token format.'));
}
resolve(token);
});
});
}
// Main entry point
async function main() {
try {
const token = await readDigitalOceanToken();
console.log('Token successfully loaded:', token);
// TODO: Use token to interact with DigitalOcean API
} catch (err) {
console.error('Error:', err.message);
}
}
main();
{
"name": "do",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment