Skip to content

Commit

Permalink
Merge pull request #7 from balena-io-modules/use-s3-handler
Browse files Browse the repository at this point in the history
Use standalone S3 Handler instead of pinejs core one
  • Loading branch information
flowzone-app[bot] authored Jan 2, 2025
2 parents 9843de8 + 700204a commit 25e73a2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
13 changes: 8 additions & 5 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { webResourceHandler } from '@balena/pinejs';
import memoize from 'memoizee';
import { getSignedUrl } from '@aws-sdk/cloudfront-signer';
import { S3Handler, type S3HandlerProps } from '@balena/pinejs-webresource-s3';
import type { WebResourceType as WebResource } from '@balena/sbvr-types';

export interface CloudFrontHandlerProps
extends webResourceHandler.S3HandlerProps {
export interface CloudFrontHandlerProps extends S3HandlerProps {
cfPublicKeyId: string;
cfSecretKey: string;
cfDistributionDomain: string;
}

export class CloudFrontHandler extends webResourceHandler.S3Handler {
const normalizeHref = (href: string) => {
return href.split('?', 1)[0];
};

export class CloudFrontHandler extends S3Handler {
private readonly cfSecretKey: string;
private readonly cfPublicKeyId: string;
private readonly cfDistributionDomain: string;
Expand Down Expand Up @@ -59,7 +62,7 @@ export class CloudFrontHandler extends webResourceHandler.S3Handler {
}

private cfGetKeyFromHref(href: string): string {
const hrefWithoutParams = webResourceHandler.normalizeHref(href);
const hrefWithoutParams = normalizeHref(href);
return hrefWithoutParams
.split('/')
.slice(3)
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@
"devDependencies": {
"@balena/lint": "^8.2.8",
"@balena/sbvr-types": "^7.1.3",
"@types/memoizee": "0.4.11",
"husky": "^9.1.7",
"lint-staged": "^15.3.0",
"typescript": "^5.7.2"
},
"dependencies": {
"@aws-sdk/cloudfront-signer": "^3.709.0",
"memoizee": "^0.4.17"
},
"peerDependencies": {
"@balena/pinejs": "^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
"@balena/pinejs-webresource-s3": "^1.0.0",
"memoizee": "0.4.17"
},
"versionist": {
"publishedAt": "2025-01-02T15:32:11.226Z"
Expand Down

0 comments on commit 25e73a2

Please sign in to comment.