Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ import {
} from '@aws-sdk/client-s3';
import { Upload } from '@aws-sdk/lib-storage';
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
import type { webResourceHandler } from '@balena/pinejs';
import { webResourceHandler } from '@balena/pinejs';

import type { WebResourceType as WebResource } from '@balena/sbvr-types';
import memoize from 'memoizee';
import { randomUUID } from 'node:crypto';
import type { AnyObject } from 'pinejs-client-core';
import { TypedError } from 'typed-error';

// TODO: remove me and import from pinejs once v17 is out
interface BeginMultipartUploadPayload {
Expand All @@ -43,7 +41,7 @@ interface CommitMultipartUploadPayload {
fileKey: string;
uploadId: string;
filename: string;
providerCommitData?: AnyObject;
providerCommitData?: Record<string, any>;
}

export interface S3HandlerProps {
Expand All @@ -61,13 +59,6 @@ const normalizeHref = (href: string) => {
return href.split('?')[0];
};

export class FileSizeExceededError extends TypedError {
name = 'FileSizeExceededError';
constructor(maxSize: number) {
super(`File size exceeded the limit of ${maxSize} bytes.`);
}
}

export class S3Handler implements webResourceHandler.WebResourceHandler {
private readonly config: S3ClientConfig;
private readonly bucket: string;
Expand Down Expand Up @@ -131,7 +122,7 @@ export class S3Handler implements webResourceHandler.WebResourceHandler {
} catch (err: any) {
resource.stream.resume();
if (size > this.maxFileSize) {
throw new FileSizeExceededError(this.maxFileSize);
throw new webResourceHandler.FileSizeExceededError(this.maxFileSize);
}
throw err;
}
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"build": "tsc",
"test": "npm run lint",
"prettify": "balena-lint -e ts --fix lib",
"lint-fix": "balena-lint -e ts --fix lib",
"lint": "balena-lint -e ts lib && npx tsc --noEmit",
"prepare": "node -e \"try { (await import('husky')).default() } catch (e) { if (e.code !== 'ERR_MODULE_NOT_FOUND') throw e }\" --input-type module"
},
Expand All @@ -29,8 +29,10 @@
"@aws-sdk/client-s3": "^3.717.0",
"@aws-sdk/lib-storage": "^3.717.0",
"@aws-sdk/s3-request-presigner": "^3.717.0",
"memoizee": "^0.4.17",
"typed-error": "^3.2.2"
"memoizee": "^0.4.17"
},
"peerDependencies": {
"@balena/pinejs": "^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^20.0.0"
},
"versionist": {
"publishedAt": "2025-01-02T15:32:49.486Z"
Expand Down
Loading