Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
do
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
do
Commits
a2390a96
Commit
a2390a96
authored
Jul 26, 2025
by
Ahmad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dsdsd
parent
31ee2ebd
Pipeline
#230
canceled with stages
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
4 deletions
+37
-4
a.js
a.js
+37
-4
No files found.
a.js
View file @
a2390a96
const
fs
=
require
(
'
fs
'
);
const
fs
=
require
(
'
fs
'
);
const
path
=
require
(
'
path
'
);
const
path
=
require
(
'
path
'
);
const
os
=
require
(
'
os
'
);
const
os
=
require
(
'
os
'
);
const
axios
=
require
(
'
axios
'
);
//
Reads and validates the DigitalOcean API token from Downloads
//
Step 1: Read & validate DigitalOcean API token
function
readDigitalOceanToken
()
{
function
readDigitalOceanToken
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
downloadsDir
=
path
.
join
(
os
.
homedir
(),
'
Downloads
'
);
const
downloadsDir
=
path
.
join
(
os
.
homedir
(),
'
Downloads
'
);
...
@@ -33,13 +34,45 @@ function readDigitalOceanToken() {
...
@@ -33,13 +34,45 @@ function readDigitalOceanToken() {
});
});
}
}
// Main entry point
// Step 2: Fetch available US regions
async
function
fetchUSRegions
(
token
)
{
try
{
const
response
=
await
axios
.
get
(
'
https://api.digitalocean.com/v2/regions
'
,
{
headers
:
{
Authorization
:
`Bearer
${
token
}
`
,
},
});
const
regions
=
response
.
data
.
regions
;
// Filter: available + US regions (e.g., nyc, sfo)
const
usRegions
=
regions
.
filter
(
(
region
)
=>
region
.
available
&&
/^
(
nyc|sfo|chi|sea|dc|atl
)
/i
.
test
(
region
.
slug
)
);
if
(
usRegions
.
length
===
0
)
{
console
.
log
(
'
No available US regions found.
'
);
}
else
{
console
.
log
(
'
Available US regions:
'
);
usRegions
.
forEach
((
region
)
=>
{
console
.
log
(
`-
${
region
.
slug
}
:
${
region
.
name
}
`
);
});
}
return
usRegions
;
}
catch
(
error
)
{
throw
new
Error
(
`Failed to fetch regions:
${
error
.
message
}
`
);
}
}
// Main
async
function
main
()
{
async
function
main
()
{
try
{
try
{
const
token
=
await
readDigitalOceanToken
();
const
token
=
await
readDigitalOceanToken
();
console
.
log
(
'
Token
successfully loaded:
'
,
token
);
console
.
log
(
'
Token
loaded.
'
);
// TODO: Call DigitalOcean API here
const
usRegions
=
await
fetchUSRegions
(
token
);
// Next: choose one of these regions to create a Droplet
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
error
(
'
Error:
'
,
err
.
message
);
console
.
error
(
'
Error:
'
,
err
.
message
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment