Skip to content

Commit 307a792

Browse files
committed
S3 cache write
1 parent 8a6323e commit 307a792

File tree

4 files changed

+33
-18
lines changed

4 files changed

+33
-18
lines changed

beebjit.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ async function beebjit(c, jsbeeb){
6868
let stdout = await exec(beebjit_cmd );
6969
console.log(beebjit_cmd);
7070
let state = await parseBeebjitState(stdout);
71-
72-
console.log(state);
7371
return state;
7472

7573

cache.js

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,39 @@
11
const BotGenesis = 1569394800; // First ever bot tweet 25 Sep 2019
2+
const AWS = require('aws-sdk');
3+
const s3 = new AWS.S3();
24

35
async function cache(toot, beebState){
46

5-
// Were assuming single thread sequential URL generation here...
6-
let num = Math.floor(Date.now()/1000) - 1569394800;
7-
let digits = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
8-
let len = Math.min(digits.length, 62);
9-
let short_url = '';
10-
while (num > 0) {
11-
short_url = digits[num % len] + result;
12-
num = parseInt(num / len, 10);
13-
}
14-
15-
16-
17-
18-
19-
return "dummy"
7+
// Were assuming single thread sequential URL generation here...
8+
let num = Math.floor(Date.now()/1000) - 1569394800;
9+
let digits = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
10+
let len = Math.min(digits.length, 62);
11+
let tag = '';
12+
while (num > 0) {
13+
tag = digits[num % len] + tag;
14+
num = parseInt(num / len, 10);
15+
}
16+
17+
18+
let body = {
19+
'v': 3,
20+
'toot': toot.prog,
21+
'mode': toot.mode,
22+
'src': toot.src,
23+
'state': beebState
24+
}
25+
26+
const params = {
27+
Bucket: "link.bbcmic.ro",
28+
Key: 'state/'+tag, // File name you want to save as in S3
29+
Body: JSON.stringify(body)
30+
};
31+
// Uploading files to the bucket
32+
await s3.upload(params).promise();
33+
console.log("Cache: link.bbcmic.ro/state/"+tag)
34+
35+
36+
return tag;
2037
}
2138

2239
module.exports = cache;

client.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ var clientID = "Cli0";
178178

179179
// Summarize toot data
180180
let tootData = {
181-
"v":3, // Mastodon era
182181
"prog":c.input,
183182
"mode":c.mode,
184183
"src": tweet.url,

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"author": "",
1212
"license": "ISC",
1313
"dependencies": {
14+
"aws-sdk": "^2.1265.0",
1415
"bad-words": "^3.0.3",
1516
"console-stamp": "^0.2.9",
1617
"dotenv": "^8.2.0",

0 commit comments

Comments
 (0)