-
Notifications
You must be signed in to change notification settings - Fork 6
/
gridsome.server.js
106 lines (84 loc) · 3.26 KB
/
gridsome.server.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
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Server API makes it possible to hook into various parts of Gridsome
// on server-side and add custom data to the GraphQL data layer.
// Learn more: https://gridsome.org/docs/server-api/
// Changes here require a server restart.
// To restart press CTRL + C in terminal and run `gridsome develop`
const axios = require('axios')
const webp = require('webp-converter');
const fs = require('fs');
const fetch = require('node-fetch');
webp.grant_permission();
// get remote blog images and convert them to webp
async function convertRemoteBlogImages() {
//get data from jfrog.com
const {data} = await axios.get(`https://jfrog.com/latest-security-posts/`)
parsedPosts = [...data]
const imageUrls = []
for (let i = 0; i < parsedPosts.length; i++) {
const post = parsedPosts[i];
const remoteURL = post.img
//get remote file
const response = await fetch(remoteURL);
const buffer = await response.buffer();
//image extension
const fileStrSplit = remoteURL.split('.')
const ext = fileStrSplit[fileStrSplit.length-1]
//write normal file locally, and add a converted webp version
fs.writeFile(`./static/latest-posts-${i}.${ext}`, buffer, () => {
console.log(`finished downloading ${remoteURL} ! | Saved to ./static/latest-posts-${i}.${ext} `)
const result = webp.cwebp(
`./static/latest-posts-${i}.${ext}`,
`./static/latest-posts-${i}.webp`,
"-q 80",
logging="-v"
);
result.then((response) => {
console.log(response);
});
});
}
}
convertRemoteBlogImages()
module.exports = function(api) {
api.loadSource(
async (store) => {
store.addMetadata("baseURL", "https://research.jfrog.com");
const domain = 'jfrog.local'
//for resting purposes on dev only
// process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
const {data} = await axios.get(`https://jfrog.com/latest-security-posts`)
const CVEPost = await axios.get(`https://jfrog.com/latest-cve-posts`)
const Log4shellPost = await axios.get(`https://jfrog.com/latest-log4shell-posts`)
const springShellPost = await axios.get(`https://jfrog.com/latest-springshell-posts`)
const NpmToolsPost = await axios.get(`https://jfrog.com/latest-npmtools-posts`)
store.addMetadata("latestPostsJSON", JSON.stringify(data))
store.addMetadata("latestCVEPostsJSON", JSON.stringify(CVEPost.data))
store.addMetadata("latestLog4ShellPostsJSON", JSON.stringify(Log4shellPost.data))
store.addMetadata("latestSpringShellPostsJSON", JSON.stringify(springShellPost.data))
store.addMetadata("latestNpmToolsPostsJSON", JSON.stringify(NpmToolsPost.data))
},
({ addSchemaTypes }) => {
addSchemaTypes(`
type Post implements Node {
id: ID!
title: String
published: Boolean
description: String
date_published: Date
last_updated: Date
xray_id: String
vul_id: String
severity: String
discovered_by: String
type: String
platform: String
downloads_text: String
cvss: String
}
`)
}
);
// api.createPages(({ createPage }) => {
// // Use the Pages API here: https://gridsome.org/docs/pages-api/
// })
};