New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@667/ghost-storage-github

Package Overview
Dependencies
Maintainers
0
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@667/ghost-storage-github - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

.github/workflows/npm_publish.yaml

47

index.js

@@ -6,2 +6,3 @@ const https = require('https')

const BaseAdapter = require('./BaseStorage')
const sharp = require('sharp')

@@ -14,3 +15,5 @@ const {

GHOST_STORAGE_GITHUB_DESTINATION,
GHOST_STORAGE_GITHUB_ORIGIN
GHOST_STORAGE_GITHUB_ORIGIN,
GHOST_STORAGE_GITHUB_IMAGE_FORMAT,
GHOST_STORAGE_GITHUB_ETAG_CACHE_SIZE
} = process.env

@@ -29,2 +32,4 @@

origin,
imageFormat,
etagCacheSize
} = config

@@ -38,2 +43,4 @@

this.origin = GHOST_STORAGE_GITHUB_ORIGIN || origin
this.imageFormat = GHOST_STORAGE_GITHUB_IMAGE_FORMAT || imageFormat
this.etagCacheSize = GHOST_STORAGE_GITHUB_ETAG_CACHE_SIZE || etagCacheSize || 10000
this.committer = {

@@ -88,2 +95,29 @@ name: 'June07',

}
async getBase64(buffer) {
if (!this.imageFormat) {
return buffer.toString('base64')
}
const { fileTypeFromBuffer } = await import('file-type')
const { mime } = await fileTypeFromBuffer(buffer)
if (/image/.test(mime) && mime.match(/image\/(.*)/)[1] !== this.imageFormat) {
return await sharp(buffer).toFormat(this.imageFormat).toBuffer()
}
return buffer.toString('base64')
}
checkSizeAndEvict() {
const keys = Object.keys(this.etags)
if (keys.length > this.etagCacheSize) {
// Sort keys by timestamp
keys.sort((a, b) => this.etags[a].timestamp - this.etags[b].timestamp)
// Remove the oldest entries until the size is within the limit
while (keys.length > this.etagCacheSize) {
const oldestKey = keys.shift()
delete this.etags[oldestKey]
}
}
}
async exists(file, targetDir) {

@@ -103,3 +137,7 @@ const sha = createHash('sha1').update(file.base64).digest('hex')

const shaResponse = createHash('sha1').update(base64Response).digest('hex')
this.etags[sha] = headers.etag
this.etags[sha] = {
timestamp: Date.now(),
etag: headers.etag
}
this.checkSizeAndEvict()

@@ -118,3 +156,5 @@ if (shaResponse === sha) {

async save(file, targetDir) {
const base64 = await readFile(file.path, 'base64')
const buffer = await readFile(file.path)
const base64 = await this.getBase64(buffer)
const filepath = await this.getUniqueFileName({ ...file, base64 }, targetDir || this.getTargetDir())

@@ -141,3 +181,2 @@ const filename = filepath.split('/').pop()

}
serve() {

@@ -144,0 +183,0 @@ return (req, res, next) => next

8

package.json
{
"name": "@667/ghost-storage-github",
"version": "1.0.0",
"version": "1.1.0",
"description": "Save Ghost Blog Content to Github",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 0"
},

@@ -27,4 +27,6 @@ "repository": {

"@octokit/plugin-throttling": "^9.3.0",
"@octokit/rest": "^21.0.0"
"@octokit/rest": "^21.0.0",
"file-type": "^19.0.0",
"sharp": "^0.33.4"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc