Skip to content

Commit

Permalink
chore: format
Browse files Browse the repository at this point in the history
  • Loading branch information
batosai committed Oct 1, 2024
1 parent 933a629 commit 01427cf
Show file tree
Hide file tree
Showing 19 changed files with 54 additions and 54 deletions.
1 change: 0 additions & 1 deletion .github/workflows/issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ on:
issue_comment:
types: [created, edited]


jobs:
notify-discord:
runs-on: ubuntu-latest
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ env:
false: 🔴

jobs:

release:
runs-on: ubuntu-latest
steps:
Expand All @@ -25,7 +24,7 @@ jobs:
uses: halvardssm/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
path: "./package.json" # optional, will use ./package.json by default
path: './package.json' # optional, will use ./package.json by default

- run: |
echo 'Release created: ${{steps.release.outputs.release_created}}' # 'true' or 'false'
Expand All @@ -43,7 +42,6 @@ jobs:
Release : ${{ env[steps.release.outputs.release_created] }}
Tag: ${{ steps.version.outputs.release_tag }}
publish-npm:
needs: release
runs-on: ubuntu-latest
Expand Down
1 change: 0 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import attachmentManager from './services/main.js'


export { configure } from './configure.js'
export { Attachment } from './src/attachments/attachment.js'
export { attachment } from './src/decorators/attachment.js'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@
"volta": {
"node": "20.17.0"
}
}
}
8 changes: 3 additions & 5 deletions src/adapters/exif.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import { fileTypeFromBuffer, fileTypeFromFile } from 'file-type'
import { bufferToTempFile, cleanObject, use } from '../utils/helpers.js'
import { attachmentManager } from '../../index.js'

export const exif = async (input: Input): Promise<Exif|undefined> => {

export const exif = async (input: Input): Promise<Exif | undefined> => {
let fileType
let buffer

Expand Down Expand Up @@ -119,9 +118,8 @@ async function imageExif(buffer: Buffer) {
return cleanObject(data)
}


async function videoExif(input: Input) {
return new Promise<Exif|undefined>(async (resolve) => {
return new Promise<Exif | undefined>(async (resolve) => {
const ffmpeg = await use('fluent-ffmpeg')

let file = input
Expand All @@ -148,7 +146,7 @@ async function videoExif(input: Input) {
dimension: {
width: data.streams[0].width,
height: data.streams[0].height,
}
},
})
})
})
Expand Down
5 changes: 4 additions & 1 deletion src/attachment_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ export class AttachmentManager {
}
}

async computeUrl(attachment: AttachmentType | AttachmentBase, signedUrlOptions?: SignedURLOptions) {
async computeUrl(
attachment: AttachmentType | AttachmentBase,
signedUrlOptions?: SignedURLOptions
) {
const disk = attachment.getDisk()
const fileVisibility = await disk.getVisibility(attachment.path!)

Expand Down
7 changes: 5 additions & 2 deletions src/attachments/attachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ export class Attachment extends AttachmentBase implements AttachmentInterface {
return super.getUrl()
}

getSignedUrl(variantNameOrOptions?: string | SignedURLOptions, signedUrlOptions?: SignedURLOptions) {
getSignedUrl(
variantNameOrOptions?: string | SignedURLOptions,
signedUrlOptions?: SignedURLOptions
) {
let variantName: string | undefined
let options: SignedURLOptions | undefined = signedUrlOptions

Expand Down Expand Up @@ -111,7 +114,7 @@ export class Attachment extends AttachmentBase implements AttachmentInterface {
this.variants.forEach((v) => {
v.setOptions({
...this.options,
variants: []
variants: [],
})
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/attachments/attachment_base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class AttachmentBase implements AttachmentBaseInterface {
if (this.url) {
return {
...this.toObject(),
url: this.url
url: this.url,
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/converters/autodetect_converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import ImageConverter from './image_converter.js'
import VideoThumnailConverter from './video_thumbnail_converter.js'

export default class AutodetectConverter extends Converter {

async handle({ input, options }: ConverterAttributes) {

let converter
let fileType

Expand All @@ -34,7 +32,7 @@ export default class AutodetectConverter extends Converter {
if (converter) {
return await converter.handle({
input,
options
options,
})
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/converters/document_thumbnail_converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ export default class DocumentThumbnailConverter extends Converter {
const converter = new ImageConverter()
return await converter.handle({
input: outputBuffer,
options
options,
})
}

return outputBuffer
} catch(err) {
} catch (err) {
logger.error({ err })
}
}
Expand All @@ -44,7 +44,7 @@ export default class DocumentThumbnailConverter extends Converter {
childProcessOptions: {
timeout: 60 * 1000,
},
binaryPaths
binaryPaths,
})

if (Buffer.isBuffer(input)) {
Expand Down
2 changes: 1 addition & 1 deletion src/converters/image_converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default class ImageConverter extends Converter {
.toBuffer()

return buffer
} catch(err) {
} catch (err) {
logger.error({ err })
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/converters/pdf_thumbnail_converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ export default class PdfThumbnailConverter extends Converter {
const converter = new ImageConverter()
return await converter.handle({
input: filePath,
options
options,
})
}

return filePath
} catch(err) {
} catch (err) {
logger.error({ err })
}
}
Expand Down
20 changes: 9 additions & 11 deletions src/converters/video_thumbnail_converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import ImageConverter from './image_converter.js'
import { bufferToTempFile, use } from '../utils/helpers.js'

export default class VideoThumbnailConvert extends Converter {

async handle({ input, options }: ConverterAttributes) {
try {
const ffmpeg = await use('fluent-ffmpeg')
Expand All @@ -27,12 +26,12 @@ export default class VideoThumbnailConvert extends Converter {
const converter = new ImageConverter()
return await converter.handle({
input: filePath,
options
options,
})
} else {
return filePath
}
} catch(err) {
} catch (err) {
logger.error({ err })
}
}
Expand All @@ -44,7 +43,7 @@ export default class VideoThumbnailConvert extends Converter {
file = await bufferToTempFile(input)
}

return new Promise<string|false>((resolve) => {
return new Promise<string | false>((resolve) => {
const folder = os.tmpdir()
const filename = `${cuid()}.png`

Expand All @@ -57,13 +56,12 @@ export default class VideoThumbnailConvert extends Converter {
}

ff.screenshots({
count: 1,
filename,
folder,
})
.on('end', () => {
resolve(path.join(folder, filename))
})
count: 1,
filename,
folder,
}).on('end', () => {
resolve(path.join(folder, filename))
})
})
}
}
8 changes: 6 additions & 2 deletions src/decorators/attachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ export const attachment = (options?: LucidOptions) => {
const defaultConfig = attachmentManager.getConfig()
const defaultOptions = {
meta: defaultConfig.meta !== undefined ? defaultConfig.meta : defaultOptionsDecorator.meta,
rename: defaultConfig.rename !== undefined ? defaultConfig.rename : defaultOptionsDecorator.rename,
preComputeUrl: defaultConfig.preComputeUrl !== undefined ? defaultConfig.preComputeUrl : defaultOptionsDecorator.preComputeUrl,
rename:
defaultConfig.rename !== undefined ? defaultConfig.rename : defaultOptionsDecorator.rename,
preComputeUrl:
defaultConfig.preComputeUrl !== undefined
? defaultConfig.preComputeUrl
: defaultOptionsDecorator.preComputeUrl,
}

if (!options || options?.meta === undefined) {
Expand Down
15 changes: 3 additions & 12 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,14 @@ export const E_CANNOT_CREATE_ATTACHMENT = createError<[key: string]>(
/**
* Is not a Buffer
*/
export const E_ISNOT_BUFFER = createError(
'Is not a Buffer',
'E_ISNOT_BUFFER'
)
export const E_ISNOT_BUFFER = createError('Is not a Buffer', 'E_ISNOT_BUFFER')

/**
* Is not a Base64
*/
export const E_ISNOT_BASE64 = createError(
'Is not a Base64',
'E_ISNOT_BASE64'
)
export const E_ISNOT_BASE64 = createError('Is not a Base64', 'E_ISNOT_BASE64')

/**
* Unable to read file
*/
export const ENOENT = createError(
'File not found',
'ENOENT'
)
export const ENOENT = createError('File not found', 'ENOENT')
6 changes: 5 additions & 1 deletion src/mixins/attachmentable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ import {
generateVariants,
preComputeUrl,
} from '../utils/actions.js'
import { clone, getAttachmentAttributeNames, getDirtyAttachmentAttributeNames } from '../utils/helpers.js'
import {
clone,
getAttachmentAttributeNames,
getDirtyAttachmentAttributeNames,
} from '../utils/helpers.js'
import { defaultStateAttributeMixin } from '../utils/default_values.js'

export const Attachmentable = <Model extends NormalizeConstructor<typeof BaseModel>>(
Expand Down
5 changes: 4 additions & 1 deletion src/types/attachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ export type Attachment = AttachmentBase & {
createVariant(key: string, input: Input): Promise<Variant>
getVariant(variantName: string): Variant | undefined
getUrl(variantName?: string): Promise<string>
getSignedUrl(variantNameOrOptions?: string | SignedURLOptions, signedUrlOptions?: SignedURLOptions): Promise<string>
getSignedUrl(
variantNameOrOptions?: string | SignedURLOptions,
signedUrlOptions?: SignedURLOptions
): Promise<string>
toObject(): AttachmentAttributes
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/default_values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const defaultOptionsDecorator = {
preComputeUrl: false,
variants: [],
meta: true,
rename: true
rename: true,
}

export const defaultStateAttributeMixin = {
Expand Down
6 changes: 4 additions & 2 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export function getAttachmentAttributeNames(modelInstance: ModelWithAttachment)

export function getDirtyAttachmentAttributeNames(modelInstance: ModelWithAttachment) {
return Object.keys(modelInstance.$dirty).filter(
(attr) => modelInstance.$dirty[attr] instanceof Attachment || modelInstance.$original[attr] instanceof Attachment
(attr) =>
modelInstance.$dirty[attr] instanceof Attachment ||
modelInstance.$original[attr] instanceof Attachment
)
}

Expand Down Expand Up @@ -99,7 +101,7 @@ export async function use(module: string) {

return result
} catch (err) {
throw new errors.E_MISSING_PACKAGE([module], { cause: err})
throw new errors.E_MISSING_PACKAGE([module], { cause: err })
}
}

Expand Down

0 comments on commit 01427cf

Please sign in to comment.