Skip to content

Commit

Permalink
Merge pull request #625 from swrlab/dev/622-remove-s3
Browse files Browse the repository at this point in the history
refact!: remove aws-sdk integration (s3)
  • Loading branch information
frytg authored Jul 10, 2024
2 parents f4d9d85 + 585aa37 commit b144758
Show file tree
Hide file tree
Showing 30 changed files with 1,590 additions and 1,967 deletions.
16 changes: 0 additions & 16 deletions .eslintrc.json

This file was deleted.

5 changes: 1 addition & 4 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
name: Linter

on:
push:
branches-ignore:
- 'dependabot/**'
workflow_call:
inputs:
install-all:
Expand Down Expand Up @@ -35,7 +32,7 @@ on:
description: 'Path to the ESLint configuration file'
required: false
type: string
default: '/.eslintrc.json'
default: '/eslint.config.mjs'

env:
CSS_FILE_NAME: /.stylelintrc.json
Expand Down
11 changes: 9 additions & 2 deletions .stylelintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
{
"defaultSeverity": "warning",
"extends": ["stylelint-config-standard-scss", "stylelint-config-recommended-vue/scss"],
"ignoreFiles": ["**/static-ui/dist/*", "**/ati-smarttag.js", "**/skycons.js"],
"extends": [
"stylelint-config-standard-scss",
"stylelint-config-recommended-vue/scss"
],
"ignoreFiles": [
"**/static-ui/dist/*",
"**/ati-smarttag.js",
"**/skycons.js"
],
"rules": {
"declaration-empty-line-before": null,
"indentation": "tab",
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ by [**SWR Audio Lab**](https://lab.swr.de/)

## Changelog

- 2024-07-10 - v2.0.0

- refact!: remove aws-sdk integration (s3)
- refact!: remove `ard:publishers` and `ard:pub-sort` scripts
- chore!: switch super-linter ESLint config default to `/eslint.config.mjs`

- 2024-05-13 - v1.3.0

- chore: update dependencies
Expand Down
44 changes: 44 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { audiolab } from '@swrlab/style-guide/eslint/index'

export default audiolab(
[
{
ignores: [],
},
{
rules: {
// previous config (does not trigger errors)
// 'import/no-extraneous-dependencies': 0,
// radix: 0,
// 'no-param-reassign': [2, { props: false }],
// 'no-restricted-syntax': 0,
// 'no-underscore-dangle': 0,
// 'no-return-assign': ['error', 'except-parens'],
// 'one-var': 0,

// should be fixed / easy to fix
'prefer-promise-reject-errors': 'off',
'n/prefer-global/process': 'off',
'n/prefer-global/buffer': 'off',
'n/no-process-exit': 'off',
'n/no-unpublished-import': 'off',
'n/no-unpublished-require': 'off',
'eslint-comments/require-description': 'off',
'vue/multi-word-component-names': 'off',
// could be fixed when converting to ESM
'import/order': 'off',
// a bit more complex to fix (but nice idea in general)
'import/no-default-export': 'off',
'no-console': 'off',
'func-names': 'off',
'jsonc/sort-keys': 'off',

// harder to fix
},
},
],
{
prettier: true,
comments: true,
}
)
36 changes: 16 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,45 +1,41 @@
{
"name": "@swrlab/utils",
"version": "1.3.0",
"version": "2.0.0-beta",
"description": "Wrapping common SWR Audio Lab utils",
"main": "./index.js",
"engines": {
"node": ">=20"
},
"repository": {
"type": "git",
"url": "https://github.com/swrlab/node-utils"
},
"author": "SWR Audio Lab <lab@swr.de>",
"license": "MIT",
"main": "./index.js",
"scripts": {
"ard:coreId": "node ./scripts/ard/coreId.js",
"ard:categories": "node -r dotenv/config scripts/ard/categories.js",
"ard:publishers": "node -r dotenv/config scripts/ard/publishers.js",
"ard:pub-sort": "node -r dotenv/config scripts/ard/sortPubByExtId.js",
"lint": "eslint .",
"test": "mocha tests/**.js -r dotenv/config",
"outdated": "yarn upgrade-interactive",
"reinstall": "rm -rf node_modules && rm yarn.lock && touch yarn.lock && yarn"
},
"author": "SWR Audio Lab <lab@swr.de>",
"license": "MIT",
"dependencies": {
"@google-cloud/storage": "^7.11.0",
"@google-cloud/storage": "^7.11.3",
"abort-controller": "^3.0.0",
"aws-sdk": "2.1618.0",
"luxon": "3.4.4",
"node-crc": "swrlab/node-crc#v2.1.0",
"undici": "6.16.1"
"undici": "6.19.2"
},
"devDependencies": {
"@swrlab/eslint-plugin-swr": "^0.3.0",
"@swrlab/swr-prettier-config": "^0.3.0",
"@swrlab/style-guide": "https://github.com/swrlab/style-guide.git",
"chai": "4.4.1",
"dotenv": "^16.4.5",
"eslint": "^8.57.0",
"eslint-plugin-json": "^3.1.0",
"mocha": "^10.4.0",
"prettier": "^3.2.5"
"eslint": "^9.6.0",
"eslint-plugin-json": "^4.0.0",
"mocha": "^10.6.0",
"prettier": "^3.3.2"
},
"engines": {
"node": ">=20"
},
"prettier": "@swrlab/swr-prettier-config",
"packageManager": "yarn@4.2.2"
"packageManager": "yarn@4.2.2",
"prettier": "@swrlab/style-guide/prettier"
}
31 changes: 9 additions & 22 deletions packages/storage-wrapper/createUrl.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable func-names */
/*
node-storage-wrapper
Expand All @@ -7,48 +6,36 @@
*/

module.exports = async function (uri, ttl, logPrefix) {
const thisLogPrefix = logPrefix ? [logPrefix, '>'] : []

if (uri.substr(0, 5).toLowerCase() === 's3://') {
// log progress
this.sdk.log(this, 'log', thisLogPrefix.concat(['storage.createUrl.aws >', uri]))

return Promise.reject(new Error('not implemented'))
}

module.exports = async function (uri, ttl) {
if (uri.substr(0, 5).toLowerCase() === 'gs://') {
// google cloud storage
const structure = uri.substr(5).split('/')
const bucket = structure.shift()
const path = structure.join('/')

// log progress
this.sdk.log(this, 'log', thisLogPrefix.concat(['storage.createUrl.gcp >', uri]))

// set config
const config = {
action: 'read',
expires: Date.now() + ttl,
}

// create link
const [url] = await this.sdk.gs.bucket(bucket).file(path).getSignedUrl(config)
const [url] = await this.sdk.gs
.bucket(bucket)
.file(path)
.getSignedUrl(config)

// return link
return Promise.resolve(url)
}

if (uri.substr(0, 7).toLowerCase() === 'http://' || uri.substr(0, 8).toLowerCase() === 'https://') {
// log progress
this.sdk.log(this, 'log', thisLogPrefix.concat(['storage.createUrl.https >', uri]))

if (
uri.substr(0, 7).toLowerCase() === 'http://' ||
uri.substr(0, 8).toLowerCase() === 'https://'
) {
// return link
return Promise.resolve(uri)
}

// log progress
this.sdk.log(this, 'log', thisLogPrefix.concat(['storage.createUrl.local >', uri]))

return Promise.reject(new Error('not implemented'))
}
47 changes: 8 additions & 39 deletions packages/storage-wrapper/delete.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable func-names */
/*
node-storage-wrapper
Expand All @@ -13,39 +12,12 @@ const deleteLocalFile = (that, filePath) =>
})
})

module.exports = async function (uri, logPrefix) {
const thisLogPrefix = logPrefix ? [logPrefix, '>'] : []
let structure, bucket, path

if (uri.substr(0, 5).toLowerCase() === 's3://') {
// aws s3 file
structure = uri.substr(5).split('/')
bucket = structure.shift()
path = structure.join('/')

// log progress
this.sdk.log(this, 'log', thisLogPrefix.concat(['storage.delete.s3 >', uri]))

// delete from aws
await this.sdk.s3
.deleteObject({
Bucket: bucket,
Key: path,
})
.promise()

// return ok
return Promise.resolve()
}

module.exports = async function (uri) {
if (uri.substr(0, 5).toLowerCase() === 'gs://') {
// google cloud storage
structure = uri.substr(5).split('/')
bucket = structure.shift()
path = structure.join('/')

// log progress
this.sdk.log(this, 'log', thisLogPrefix.concat(['storage.delete.gs >', uri]))
const structure = uri.substr(5).split('/')
const bucket = structure.shift()
const path = structure.join('/')

// delete from gcp
await this.sdk.gs.bucket(bucket).file(path).delete(path)
Expand All @@ -54,17 +26,14 @@ module.exports = async function (uri, logPrefix) {
return Promise.resolve()
}

if (uri.substr(0, 7).toLowerCase() === 'http://' || uri.substr(0, 8).toLowerCase() === 'https://') {
// log progress
this.sdk.log(this, 'log', thisLogPrefix.concat(['storage.delete.https (not possible) >', uri]))

if (
uri.substr(0, 7).toLowerCase() === 'http://' ||
uri.substr(0, 8).toLowerCase() === 'https://'
) {
// return ok
return Promise.resolve()
}

// log progress
this.sdk.log(this, 'log', thisLogPrefix.concat(['storage.delete.local >', uri]))

// delete file
await deleteLocalFile(this, uri)

Expand Down
38 changes: 3 additions & 35 deletions packages/storage-wrapper/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
/* eslint-disable global-require */
/*
node-storage-wrapper
*/

// load node utils
const AWS = require('aws-sdk')
const fs = require('fs')
const fs = require('node:fs')
const { Storage } = require('@google-cloud/storage')

// create wrapper
function StorageWrapper(config) {
// check config
if (!config || !config.gs) return Promise.reject(new Error('storage config invalid'))
if (!config || !config.gs)
return Promise.reject(new Error('storage config invalid'))

// enable SDKs
this.sdk = {}
Expand All @@ -24,27 +23,6 @@ function StorageWrapper(config) {
// load google cloud storage sdk
this.sdk.gs = new Storage(config.gs)

// load aws sdk
if (config.s3) {
this.sdk.s3 = new AWS.S3(config.s3)
}

// configure logging
this.config = {
logging: config.logging,
}

// set logging
this.sdk.log = (that, level, message) => {
let thisMessage
if (message instanceof Array) thisMessage = message.join(' ')
else thisMessage = message

if (level === 'log' && that.config.logging) console.log(thisMessage)
else if (level === 'warn' && that.config.logging) console.warn(thisMessage)
else if (level === 'error' && that.config.logging) console.error(thisMessage)
}

// import functions
this.createUri = require('./createUri')
this.createUrl = require('./createUrl')
Expand All @@ -53,16 +31,6 @@ function StorageWrapper(config) {
this.load = require('./load')
this.move = require('./move')
this.save = require('./save')

// log progress
this.sdk.log(this, 'log', [
'storage.index',
'loaded config',
JSON.stringify({
gs: config.gs ? config.gs.projectId : null,
s3: config.s3 ? { accessKeyId: config.s3.accessKeyId, region: config.s3.region } : null,
}),
])
}

// export
Expand Down
Loading

0 comments on commit b144758

Please sign in to comment.