forked from sizovs/mustread-data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.js
35 lines (28 loc) · 919 Bytes
/
store.js
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
const { Storage } = require('@google-cloud/storage');
const BUCKET_NAME = 'static.mustread.tech'
const storage = new Storage({ projectId: 'mustread-tech' })
const bucket = storage.bucket(BUCKET_NAME)
const saveFile = async (name, content, contentType) => {
const file = bucket.file(name)
await file.save(content)
await file.setMetadata({ cacheControl: 'no-cache', contentType: contentType, contentDisposition: `inline; filename="${name}"` })
await file.makePublic()
}
module.exports = async (stats, rss) => {
const bucketExists = await bucket.exists()
if (!bucketExists) {
await bucket.create()
}
await bucket.setMetadata({
cors: [
{
origin: ['*'],
method: ['*'],
responseHeader: ["Content-Type"],
maxAgeSeconds: 3600
}
]
})
await saveFile('stats.json', stats, 'application/json')
await saveFile('rss.xml', rss, 'application/xml')
}