Skip to content
Draft
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
7 changes: 2 additions & 5 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"@smithy/node-http-handler": "4.7.2",
"accepts": "1.3.8",
"ajv": "8.20.0",
"archiver": "7.0.1",
"archiver": "8.0.0",
"async-mutex": "0.5.0",
"bcryptjs": "3.0.3",
"blurhash": "2.0.5",
Expand All @@ -90,7 +90,7 @@
"chalk-template": "1.1.2",
"chokidar": "5.0.0",
"color-convert": "3.1.3",
"content-disposition": "1.1.0",
"content-disposition": "2.0.0",
"date-fns": "4.1.0",
"deep-email-validator": "0.1.27",
"fastify": "5.8.5",
Expand Down Expand Up @@ -162,10 +162,7 @@
"@rollup/plugin-esm-shim": "0.1.8",
"@sentry/vue": "10.53.1",
"@types/accepts": "1.3.7",
"@types/archiver": "7.0.0",
"@types/body-parser": "1.19.6",
"@types/color-convert": "3.0.1",
"@types/content-disposition": "0.5.9",
"@types/fluent-ffmpeg": "2.1.28",
"@types/http-link-header": "1.0.7",
"@types/js-yaml": "4.0.9",
Expand Down
162 changes: 162 additions & 0 deletions packages/backend/src/@types/archiver.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/*
* SPDX-FileCopyrightText: Dolan Miu, Crevil, Piotr Błażejewicz, Michael J Walsh
* SPDX-License-Identifier: MIT
*/

// TO BE REMOVED: https://github.com/archiverjs/node-archiver/pull/842

declare module "archiver" {
/*
* Based on
* https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/archiver/index.d.ts
*/
import * as fs from 'fs';
import * as stream from 'stream';
import * as ReaddirGlob from 'readdir-glob';
import { ZlibOptions } from 'zlib';

type Partial<T> = {
[P in keyof T]?: T[P];
};

// This library adds `cwd` to the options
export type GlobOptions = ReaddirGlob.Options & { cwd?: string };

export interface EntryData {
/** Sets the entry name including internal path */
name: string;
/** Sets the entry date */
date?: Date | string | undefined;
/** Sets the entry permissions */
mode?: number | undefined;
/**
* Sets a path prefix for the entry name.
* Useful when working with methods like `directory` or `glob`
*/
prefix?: string | undefined;
/**
* Sets the fs stat data for this entry allowing
* for reduction of fs stat calls when stat data is already known
*/
stats?: fs.Stats | undefined;
}

export interface ZipEntryData extends EntryData {
/** Sets the compression method to STORE */
store?: boolean | undefined;
}

export type TarEntryData = EntryData;

export interface ProgressData {
entries: {
total: number;
processed: number;
};
fs: {
totalBytes: number;
processedBytes: number;
};
}

/** A function that lets you either opt out of including an entry (by returning false), or modify the contents of an entry as it is added (by returning an EntryData) */
export type EntryDataFunction = (entry: EntryData) => false | EntryData;

export class ArchiverError extends Error {
code: string; // Since archiver format support is modular, we cannot enumerate all possible error codes, as the modules can throw arbitrary ones.
data: any;
path?: any;

constructor(code: string, data: any);
}

export class Archiver extends stream.Transform {
constructor(options?: ArchiverOptions);

abort(): this;
append(
source: stream.Readable | Buffer | string,
data?: EntryData | ZipEntryData | TarEntryData,
): this;

/**
* If false is passed for destpath, the path of a chunk of data in the archive is set
* to the root. If no destpath is provided the dirpath is used.
*/
directory(
dirpath: string,
destpath?: false | string,
data?: Partial<EntryData> | EntryDataFunction,
): this;
file(filename: string, data: EntryData): this;
glob(pattern: string, options?: GlobOptions, data?: Partial<EntryData>): this;
finalize(): Promise<void>;

setFormat(format: string): this;
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
setModule(module: Function): this;

pointer(): number;
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
use(plugin: Function): this;

symlink(filepath: string, target: string, mode?: number): this;

on(
event: "error" | "warning",
listener: (error: ArchiverError) => void,
): this;
on(event: "data", listener: (data: Buffer) => void): this;
on(event: "progress", listener: (progress: ProgressData) => void): this;
on(event: "close" | "drain" | "finish", listener: () => void): this;
on(event: "pipe" | "unpipe", listener: (src: stream.Readable) => void): this;
on(event: "entry", listener: (entry: EntryData) => void): this;
on(event: string, listener: (...args: any[]) => void): this;
}

export type ArchiverOptions = CoreOptions &
TransformOptions &
ZipOptions &
TarOptions;

export interface CoreOptions {
statConcurrency?: number | undefined;
}

export interface TransformOptions {
allowHalfOpen?: boolean | undefined;
readableObjectMode?: boolean | undefined;
writeableObjectMode?: boolean | undefined;
decodeStrings?: boolean | undefined;
encoding?: string | undefined;
highWaterMark?: number | undefined;
objectmode?: boolean | undefined;
}

export interface ZipOptions {
comment?: string | undefined;
forceLocalTime?: boolean | undefined;
forceZip64?: boolean | undefined;
/** @default false */
namePrependSlash?: boolean | undefined;
store?: boolean | undefined;
zlib?: ZlibOptions | undefined;
}

export interface TarOptions {
gzip?: boolean | undefined;
gzipOptions?: ZlibOptions | undefined;
}

export class ZipArchive extends Archiver {
constructor(options?: ArchiverOptions & ZipOptions);
}

export class TarArchive extends Archiver {
constructor(options?: ArchiverOptions & TarOptions);
}

export class JsonArchive extends Archiver {
constructor(options?: ArchiverOptions);
}
}
4 changes: 2 additions & 2 deletions packages/backend/src/misc/content-disposition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/

import cd from 'content-disposition';
import { create } from 'content-disposition';

export function contentDisposition(type: 'inline' | 'attachment', filename: string): string {
const fallback = filename.replace(/[^\w.-]/g, '_');
return cd(filename, { type, fallback });
return create(filename, { type, fallback });
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Inject, Injectable } from '@nestjs/common';
import { IsNull } from 'typeorm';
import { format as dateFormat } from 'date-fns';
import mime from 'mime-types';
import archiver from 'archiver';
import { ZipArchive } from 'archiver';
import { DI } from '@/di-symbols.js';
import type { EmojisRepository, UsersRepository } from '@/models/_.js';
import type { Config } from '@/config.js';
Expand Down Expand Up @@ -126,7 +126,7 @@ export class ExportCustomEmojisProcessorService {
const [archivePath, archiveCleanup] = await createTemp();
await new Promise<void>((resolve) => {
const archiveStream = fs.createWriteStream(archivePath);
const archive = archiver('zip', {
const archive = new ZipArchive({
zlib: { level: 0 },
});
archiveStream.on('close', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/icons-subsetter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"dependencies": {
"@tabler/icons-webfont": "3.35.0",
"harfbuzzjs": "0.10.3",
"harfbuzzjs": "1.1.0",
"tsx": "4.22.0",
"wawoff2": "2.0.1"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/icons-subsetter/src/subsetter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

const {
instance: { exports: harfbuzzWasm },
}: any = await WebAssembly.instantiate(await fsp.readFile('./node_modules/harfbuzzjs/hb-subset.wasm'));
}: any = await WebAssembly.instantiate(await fsp.readFile('./node_modules/harfbuzzjs/dist/harfbuzz-subset.wasm'));

Check warning on line 14 in packages/icons-subsetter/src/subsetter.ts

View workflow job for this annotation

GitHub Actions / lint (icons-subsetter)

Unexpected any. Specify a different type

const heapu8 = new Uint8Array(harfbuzzWasm.memory.buffer);

Expand Down
Loading
Loading