-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublishPSS.js
More file actions
executable file
·64 lines (55 loc) · 1.88 KB
/
publishPSS.js
File metadata and controls
executable file
·64 lines (55 loc) · 1.88 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env node
import { Agent } from '@atproto/api';
import dotenv from 'dotenv';
dotenv.config();
async function publishPSS(agent, host) {
try {
console.log(`Publishing sync server location: ${host}`);
const response = await agent.api.com.atproto.repo.putRecord({
repo: agent.session.did,
collection: 'xyz.groundmist.sync',
record: {
host: host,
},
rkey: agent.session.did
});
console.log(`Published sync server location successfully!`);
console.log(`URI: ${response.data.uri}`);
console.log(`CID: ${response.data.cid}`);
console.log(`Validation status: ${response.data.validationStatus}`);
} catch (err) {
console.error(`Error publishing sync server location: ${host}`, err);
}
}
async function main() {
// Expect the sync server host as the first argument.
const host = process.argv[2];
if (!host) {
console.error('Please provide the host server where your sync server is located as the first argument.');
process.exit(1);
}
// Check environment variables.
const service = process.env.PDS_URL;
const handle = process.env.HANDLE;
const password = process.env.PASSWORD;
if (!service || !handle || !password) {
console.error('Please set PDS_URL, HANDLE, and PASSWORD environment variables.');
process.exit(1);
}
// Initialize the AT Protocol agent.
const agent = new Agent({ service });
try {
await agent.login({ identifier: handle, password });
console.log(`Logged in as ${handle}`);
} catch (err) {
console.error('Login failed:', err);
process.exit(1);
}
try {
await publishPSS(agent, host);
} catch (err) {
console.error('Error reading lexicons directory:', err);
process.exit(1);
}
}
main();