Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
063905bfaa | |||
f1ad45289a | |||
193e174fd7 | |||
703d21c426 | |||
2d83ebac4d | |||
7454a52d03 | |||
1e93429186 | |||
ee926e18a7 | |||
02a6656869 | |||
b07aba76e9 | |||
7fdeed160a | |||
c6cd1dc38f | |||
d2a47f403e | |||
c8ab607959 | |||
8170877c55 | |||
99182bdb69 | |||
d1393c5128 | |||
fc92f0f3e8 |
66
.gitea/workflows/default_nottags.yaml
Normal file
66
.gitea/workflows/default_nottags.yaml
Normal file
@ -0,0 +1,66 @@
|
||||
name: Default (not tags)
|
||||
|
||||
on:
|
||||
push:
|
||||
tags-ignore:
|
||||
- '**'
|
||||
|
||||
env:
|
||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||
|
||||
jobs:
|
||||
security:
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Install pnpm and npmci
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
|
||||
- name: Run npm prepare
|
||||
run: npmci npm prepare
|
||||
|
||||
- name: Audit production dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --prod
|
||||
continue-on-error: true
|
||||
|
||||
- name: Audit development dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --dev
|
||||
continue-on-error: true
|
||||
|
||||
test:
|
||||
if: ${{ always() }}
|
||||
needs: security
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Test stable
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm test
|
||||
|
||||
- name: Test build
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm build
|
124
.gitea/workflows/default_tags.yaml
Normal file
124
.gitea/workflows/default_tags.yaml
Normal file
@ -0,0 +1,124 @@
|
||||
name: Default (tags)
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
|
||||
env:
|
||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||
|
||||
jobs:
|
||||
security:
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Audit production dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --prod
|
||||
continue-on-error: true
|
||||
|
||||
- name: Audit development dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --dev
|
||||
continue-on-error: true
|
||||
|
||||
test:
|
||||
if: ${{ always() }}
|
||||
needs: security
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Test stable
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm test
|
||||
|
||||
- name: Test build
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm build
|
||||
|
||||
release:
|
||||
needs: test
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Release
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm publish
|
||||
|
||||
metadata:
|
||||
needs: test
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
continue-on-error: true
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Code quality
|
||||
run: |
|
||||
npmci command npm install -g typescript
|
||||
npmci npm install
|
||||
|
||||
- name: Trigger
|
||||
run: npmci trigger
|
||||
|
||||
- name: Build docs and upload artifacts
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
pnpm install -g @git.zone/tsdoc
|
||||
npmci command tsdoc
|
||||
continue-on-error: true
|
@ -3,10 +3,10 @@
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "smartjimp",
|
||||
"description": "a tool fr working with images in TypeScript",
|
||||
"npmPackagename": "@pushrocks/smartjimp",
|
||||
"npmPackagename": "@push.rocks/smartjimp",
|
||||
"license": "MIT",
|
||||
"projectDomain": "push.rocks"
|
||||
}
|
||||
|
44
package.json
44
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartjimp",
|
||||
"version": "1.0.4",
|
||||
"name": "@push.rocks/smartjimp",
|
||||
"version": "1.0.12",
|
||||
"private": false,
|
||||
"description": "a tool fr working with images in TypeScript",
|
||||
"main": "dist_ts/index.js",
|
||||
@ -9,24 +9,28 @@
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild)",
|
||||
"build": "(tsbuild --allowimplicitany)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.0.22",
|
||||
"@gitzone/tsrun": "^1.2.39",
|
||||
"@gitzone/tstest": "^1.0.15",
|
||||
"@pushrocks/tapbundle": "^5.0.4",
|
||||
"@types/node": "^18.11.18"
|
||||
"@git.zone/tsbuild": "^2.1.66",
|
||||
"@git.zone/tsrun": "^1.2.44",
|
||||
"@git.zone/tstest": "^1.0.77",
|
||||
"@push.rocks/tapbundle": "^5.0.8",
|
||||
"@types/node": "^20.10.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pushrocks/levelcache": "^3.0.3",
|
||||
"@pushrocks/smartfile": "^10.0.7",
|
||||
"@pushrocks/smarthash": "^3.0.1",
|
||||
"@pushrocks/smartpath": "^5.0.5",
|
||||
"@pushrocks/smartrequest": "^2.0.11",
|
||||
"@types/sharp": "^0.31.1",
|
||||
"sharp": "^0.31.3"
|
||||
"@img/sharp-darwin-arm64": "^0.33.0",
|
||||
"@img/sharp-darwin-x64": "^0.33.0",
|
||||
"@img/sharp-linux-arm64": "^0.33.0",
|
||||
"@img/sharp-linux-x64": "^0.33.0",
|
||||
"@img/sharp-win32-x64": "^0.33.0",
|
||||
"@push.rocks/levelcache": "^3.0.3",
|
||||
"@push.rocks/smartfile": "^11.0.4",
|
||||
"@push.rocks/smarthash": "^3.0.4",
|
||||
"@push.rocks/smartpath": "^5.0.5",
|
||||
"@push.rocks/smartrequest": "^2.0.15",
|
||||
"sharp": "^0.33.0"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
@ -43,5 +47,13 @@
|
||||
"type": "module",
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
]
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://gitlab.com/push.rocks/smartjimp.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://gitlab.com/push.rocks/smartjimp/issues"
|
||||
},
|
||||
"homepage": "https://gitlab.com/push.rocks/smartjimp#readme"
|
||||
}
|
||||
|
5269
pnpm-lock.yaml
generated
5269
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
12
readme.md
12
readme.md
@ -1,8 +1,8 @@
|
||||
# @pushrocks/smartjimp
|
||||
# @push.rocks/smartjimp
|
||||
a tool fr working with images in TypeScript
|
||||
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartjimp)
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@push.rocks/smartjimp)
|
||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartjimp)
|
||||
* [github.com (source mirror)](https://github.com/pushrocks/smartjimp)
|
||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartjimp/)
|
||||
@ -13,14 +13,14 @@ Status Category | Status Badge
|
||||
-- | --
|
||||
GitLab Pipelines | [](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||
npm | [](https://lossless.cloud)
|
||||
npm | [](https://lossless.cloud)
|
||||
Snyk | [](https://lossless.cloud)
|
||||
TypeScript Support | [](https://lossless.cloud)
|
||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
Code Style | [](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||
|
||||
## Usage
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import * as smartjimp from '../ts/index.js';
|
||||
import * as smartfile from '@pushrocks/smartfile';
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
|
||||
let testSmartJimp: smartjimp.SmartJimp;
|
||||
|
||||
@ -10,8 +10,9 @@ tap.test('first test', async () => {
|
||||
});
|
||||
|
||||
tap.test('should be able to create a master', async () => {
|
||||
const convertedAsset = await testSmartJimp.getFromUrl('https://images.unsplash.com/photo-1673276628202-737bf3020ac2?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=3774&q=80', {width: 200});
|
||||
(await smartfile.Smartfile.fromBuffer('.nogit/result.jpeg', convertedAsset)).write();
|
||||
const smartfileInstance = await smartfile.SmartFile.fromUrl('https://images.unsplash.com/photo-1673276628202-737bf3020ac2?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=3774&q=80')
|
||||
const convertedAsset = await testSmartJimp.getFromSmartfile(smartfileInstance, {width: 500});
|
||||
(await smartfile.SmartFile.fromBuffer('.nogit/result.avif', convertedAsset)).write();
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
@ -2,7 +2,7 @@
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@pushrocks/smartjimp',
|
||||
version: '1.0.4',
|
||||
name: '@push.rocks/smartjimp',
|
||||
version: '1.0.12',
|
||||
description: 'a tool fr working with images in TypeScript'
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import * as plugins from './smartjimp.plugins.js';
|
||||
|
||||
export interface IDimensions {
|
||||
export interface IAssetVariation {
|
||||
format?: 'avif' | 'webp' | 'png';
|
||||
width?: number;
|
||||
height?: number;
|
||||
}
|
||||
@ -16,64 +17,40 @@ export class SmartJimp {
|
||||
* get a key that is unique for a wanted asset variation
|
||||
*/
|
||||
private getCacheKey(
|
||||
sourceTypeArg: 'path' | 'url' | 'smartfile',
|
||||
sourceTypeArg: 'streamfile' | 'smartfile',
|
||||
sourceIdArg: string,
|
||||
wantedDimensionsArg?: IDimensions
|
||||
assetVariationArg?: IAssetVariation
|
||||
) {
|
||||
return `${sourceTypeArg}_${sourceIdArg}_${
|
||||
wantedDimensionsArg
|
||||
? `${wantedDimensionsArg.width || 'auto' }x${wantedDimensionsArg.height || 'auto'}`
|
||||
assetVariationArg
|
||||
? `${assetVariationArg.width || 'auto' }x${assetVariationArg.height || 'auto'}`
|
||||
: 'original'
|
||||
}`;
|
||||
}
|
||||
|
||||
private async computeAssetVariation(assetBuffer: Buffer, wantedDimensions?: IDimensions) {
|
||||
if (!wantedDimensions) {
|
||||
return assetBuffer;
|
||||
public async computeAssetVariation(assetBufferArg: Buffer, assetVariationArg?: IAssetVariation) {
|
||||
if (!assetVariationArg) {
|
||||
return assetBufferArg;
|
||||
}
|
||||
let sharpImage = plugins.sharp(assetBuffer);
|
||||
sharpImage = sharpImage.resize(wantedDimensions.width, wantedDimensions.height);
|
||||
const result = await sharpImage.resize(wantedDimensions.width, wantedDimensions.height).jpeg().toBuffer();
|
||||
return result;
|
||||
}
|
||||
|
||||
public async getFromPath(pathArg: string, wantedDimensionsArg?: IDimensions) {
|
||||
const cacheKey = this.getCacheKey('path', pathArg, wantedDimensionsArg);
|
||||
const existingCacheEntry = await this.levelCache.retrieveCacheEntryByKey(cacheKey);
|
||||
if (existingCacheEntry) {
|
||||
return existingCacheEntry.contents;
|
||||
} else {
|
||||
const originalAssetSmartfile = await plugins.smartfile.Smartfile.fromFilePath(pathArg);
|
||||
const computedAssetBuffer = await this.computeAssetVariation(originalAssetSmartfile.contentBuffer, wantedDimensionsArg);
|
||||
this.levelCache.storeCacheEntryByKey(cacheKey, new plugins.levelcache.CacheEntry({
|
||||
contents: computedAssetBuffer,
|
||||
ttl: 600000
|
||||
}));
|
||||
return computedAssetBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
public async getFromUrl(urlArg: string, wantedDimensionsArg?: IDimensions) {
|
||||
const cacheKey = this.getCacheKey('url', urlArg, wantedDimensionsArg);
|
||||
const existingCacheEntry = await this.levelCache.retrieveCacheEntryByKey(cacheKey);
|
||||
if (existingCacheEntry) {
|
||||
return existingCacheEntry.contents;
|
||||
} else {
|
||||
const originalAssetBuffer = (await plugins.smartrequest.getBinary(urlArg)).body;
|
||||
const computedAssetBuffer = await this.computeAssetVariation(originalAssetBuffer, wantedDimensionsArg);
|
||||
this.levelCache.storeCacheEntryByKey(cacheKey, new plugins.levelcache.CacheEntry({
|
||||
contents: computedAssetBuffer,
|
||||
ttl: 600000
|
||||
}));
|
||||
return computedAssetBuffer;
|
||||
let sharpImage = plugins.sharp(assetBufferArg);
|
||||
sharpImage = sharpImage.resize(assetVariationArg.width, assetVariationArg.height);
|
||||
const resultResize = sharpImage.resize(assetVariationArg.width, assetVariationArg.height);
|
||||
switch (assetVariationArg.format) {
|
||||
case 'avif':
|
||||
sharpImage = resultResize.avif();
|
||||
case 'webp':
|
||||
sharpImage = resultResize.webp();
|
||||
case 'png':
|
||||
sharpImage = resultResize.png();
|
||||
}
|
||||
return sharpImage.toBuffer();
|
||||
}
|
||||
|
||||
public async getFromSmartfile(
|
||||
smartfileArg: plugins.smartfile.Smartfile,
|
||||
wantedDimensionsArg?: IDimensions
|
||||
smartfileArg: plugins.smartfile.SmartFile,
|
||||
wantedDimensionsArg?: IAssetVariation
|
||||
) {
|
||||
const cacheKey = this.getCacheKey('url', await smartfileArg.getHash(), wantedDimensionsArg);
|
||||
const cacheKey = this.getCacheKey('smartfile', await smartfileArg.getHash(), wantedDimensionsArg);
|
||||
const existingCacheEntry = await this.levelCache.retrieveCacheEntryByKey(cacheKey);
|
||||
if (existingCacheEntry) {
|
||||
return existingCacheEntry.contents;
|
||||
@ -86,4 +63,11 @@ export class SmartJimp {
|
||||
return computedAssetBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
public async createAvifImageFromBuffer(bufferArg: Buffer) {
|
||||
const sharpImage = plugins.sharp(bufferArg);
|
||||
const result = await sharpImage.avif().toBuffer();
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,11 +4,11 @@ import * as path from 'path';
|
||||
export { path };
|
||||
|
||||
// @pushrocks scope
|
||||
import * as levelcache from '@pushrocks/levelcache';
|
||||
import * as smartfile from '@pushrocks/smartfile';
|
||||
import * as smarthash from '@pushrocks/smarthash';
|
||||
import * as smartpath from '@pushrocks/smartpath';
|
||||
import * as smartrequest from '@pushrocks/smartrequest';
|
||||
import * as levelcache from '@push.rocks/levelcache';
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
import * as smarthash from '@push.rocks/smarthash';
|
||||
import * as smartpath from '@push.rocks/smartpath';
|
||||
import * as smartrequest from '@push.rocks/smartrequest';
|
||||
|
||||
export { levelcache, smartpath, smarthash, smartfile, smartrequest };
|
||||
|
||||
|
@ -3,8 +3,12 @@
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "ES2022",
|
||||
"moduleResolution": "nodenext",
|
||||
"esModuleInterop": true
|
||||
}
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true
|
||||
},
|
||||
"exclude": [
|
||||
"dist_*/**/*.d.ts"
|
||||
]
|
||||
}
|
||||
|
Reference in New Issue
Block a user