Repository: directus/directus
File: app/src/utils/upload-file.ts (TypeScript)

Code before:
import { getRootPath } from '@/utils/get-root-path';
import { notify } from '@/utils/notify';
import { DEFAULT_CHUNK_SIZE } from '@directus/constants';
import type { File } from '@directus/types';
import type { AxiosProgressEvent } from 'axios';
import type { PreviousUpload } from 'tus-js-client';
import { Upload } from 'tus-js-client';
import { unexpectedError } from './unexpected-error';

export async function uploadFile(
	file: globalThis.File,
	options?: {
		onProgressChange?: (percentage: number) => void;
		onChunkedUpload?: (controller: Upload) => void;
		notifications?: boolean;
		preset?: Partial<File>;
		fileId?: string;
		requirePreviousUpload?: boolean;
	},
): Promise<File | undefined> {
	const progressHandler = options?.onProgressChange || (() => undefined);

	const server = useServerStore();
	let notified = false;

	if (server.info.uploads?.tusEnabled) {
		const fileInfo: Partial<File> = { ...(options?.preset ?? {}) };

		if (options?.fileId) {
			fileInfo.id = options?.fileId;
		}

		fileInfo.filename_download = file.name;
		fileInfo.type = file.type;

		return new Promise((resolve, reject) => {
			const upload = new Upload(file, {
				endpoint: getRootPath() + `files/tus`,
				chunkSize: server.info.uploads?.chunkSize ?? DEFAULT_CHUNK_SIZE,
				metadata: fileInfo as Record<string, string>,
				// Allow user to re-upload of the same file
				// https://github.com/tus/tus-js-client/blob/main/docs/api.md#removefingerprintonsuccess
				removeFingerprintOnSuccess: true,
				onBeforeRequest(req) {
					const xml = req.getUnderlyingObject();
					xml.withCredentials = true;
				},
				onError(error) {
					reject(error);
					emitter.emit(Events.tusResumableUploadsChanged);
				},

Review comment (suggestion):
Let's be explicit here (assuming it was renamed to `tus`):
```suggestion
	if (server.info.uploads?.tus === true) {
```

Code after:
import { Upload } from 'tus-js-client';
import { unexpectedError } from './unexpected-error';
import api from '@/api';
import { emitter, Events } from '@/events';
import { i18n } from '@/lang';
import { useServerStore } from '@/stores/server';
import { getRootPath } from '@/utils/get-root-path';
import { notify } from '@/utils/notify';

export async function uploadFile(
	file: globalThis.File,
	options?: {
		onProgressChange?: (percentage: number) => void;
		onChunkedUpload?: (controller: Upload) => void;
		notifications?: boolean;
		preset?: Partial<File>;
		fileId?: string;
		requirePreviousUpload?: boolean;
	},
): Promise<File | undefined> {
	const progressHandler = options?.onProgressChange || (() => undefined);

	const server = useServerStore();
	let notified = false;

	if (server.info.uploads?.tus === true) {
		const fileInfo: Partial<File> = { ...(options?.preset ?? {}) };

		if (options?.fileId) {
			fileInfo.id = options?.fileId;
		}

		fileInfo.filename_download = file.name;
		fileInfo.type = file.type;

		return new Promise((resolve, reject) => {
			const upload = new Upload(file, {
				endpoint: getRootPath() + `files/tus`,
				chunkSize: server.info.uploads?.chunkSize ?? DEFAULT_CHUNK_SIZE,
				metadata: fileInfo as Record<string, string>,
				// Allow user to re-upload of the same file
				// https://github.com/tus/tus-js-client/blob/main/docs/api.md#removefingerprintonsuccess
				removeFingerprintOnSuccess: true,
				onBeforeRequest(req) {
					const xml = req.getUnderlyingObject();
					xml.withCredentials = true;
				},
				onError(error) {
					reject(error);
					emitter.emit(Events.tusResumableUploadsChanged);
				},