-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.ts
More file actions
37 lines (30 loc) · 1.03 KB
/
example.ts
File metadata and controls
37 lines (30 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import path from 'node:path';
import { ServerManager } from './dist/index.mjs';
const servers = new ServerManager({
root: './servers'
});
const versions = await servers.downloads.paper.fetchVersions();
const builds = await servers.downloads.paper.fetchBuilds(versions.first()![0]);
const build = builds[0];
if (!build) throw new Error('No builds found');
console.log('Downloading server...');
const directory = path.join(servers.root, 'server');
await servers.downloads.download(
build.downloads['server:default'].url,
{
directory,
filename: 'server.jar',
onProgress: (progress) => {
if (progress.size) {
const percentage = (progress.progress / progress.size) * 100;
console.log(`Downloaded ${percentage.toFixed(2)}%`);
} else {
console.log(`Downloaded ${progress.progress} bytes`);
}
},
checksum: {
type: 'sha256',
hash: build.downloads['server:default'].checksums.sha256
}
}
);