Repository: directus/directus
File: api/src/services/assets.ts (TypeScript)

Code before:
import { useEnv } from '@directus/env';
import {
	ForbiddenError,
	IllegalAssetTransformationError,
	RangeNotSatisfiableError,
	ServiceUnavailableError,
} from '@directus/errors';
import type { Range, Stat } from '@directus/storage';
import type { Accountability, File } from '@directus/types';
import type { Knex } from 'knex';
import { clamp } from 'lodash-es';
import { contentType } from 'mime-types';
import type { Readable } from 'node:stream';
import hash from 'object-hash';
import path from 'path';
import { SUPPORTED_IMAGE_TRANSFORM_FORMATS } from '../constants.js';
import getDatabase from '../database/index.js';
import { useLogger } from '../logger/index.js';
import { getStorage } from '../storage/index.js';
import type { AbstractServiceOptions, Transformation, TransformationSet } from '../types/index.js';
import { getMilliseconds } from '../utils/get-milliseconds.js';
import { isValidUuid } from '../utils/is-valid-uuid.js';
import * as TransformationUtils from '../utils/transformations.js';
import { AuthorizationService } from './authorization.js';
import { FilesService } from './files.js';
import { useSharp, sharp } from '../utils/use-sharp.js';

const env = useEnv();
const logger = useLogger();

export class AssetsService {
	knex: Knex;
	accountability: Accountability | null;
	authorizationService: AuthorizationService;
	filesService: FilesService;

	constructor(options: AbstractServiceOptions) {
		this.knex = options.knex || getDatabase();
		this.accountability = options.accountability || null;
		this.filesService = new FilesService({ ...options, accountability: null });
		this.authorizationService = new AuthorizationService(options);
	}

	async getAsset(
		id: string,
		transformation?: TransformationSet,
		range?: Range,
	): Promise<{ stream: Readable; file: any; stat: Stat }> {
		const storage = await getStorage();

		const publicSettings = await this.knex

Review comment (suggestion):
I think I'd still prefer the direct import of `sharp` for the remaining use, like this:
```js
import sharp from 'sharp';
import { useSharp } from '../utils/use-sharp.js';
```

Code after:
import { useEnv } from '@directus/env';
import {
	ForbiddenError,
	IllegalAssetTransformationError,
	RangeNotSatisfiableError,
	ServiceUnavailableError,
} from '@directus/errors';
import type { Range, Stat } from '@directus/storage';
import type { Accountability, File } from '@directus/types';
import type { Knex } from 'knex';
import { clamp } from 'lodash-es';
import { contentType } from 'mime-types';
import type { Readable } from 'node:stream';
import hash from 'object-hash';
import path from 'path';
import sharp from 'sharp';
import { SUPPORTED_IMAGE_TRANSFORM_FORMATS } from '../constants.js';
import getDatabase from '../database/index.js';
import { useLogger } from '../logger/index.js';
import { getStorage } from '../storage/index.js';
import type { AbstractServiceOptions, Transformation, TransformationSet } from '../types/index.js';
import { getMilliseconds } from '../utils/get-milliseconds.js';
import { isValidUuid } from '../utils/is-valid-uuid.js';
import * as TransformationUtils from '../utils/transformations.js';
import { AuthorizationService } from './authorization.js';
import { FilesService } from './files.js';
import { getSharpInstance } from './files/lib/get-sharp-instance.js';

const env = useEnv();
const logger = useLogger();

export class AssetsService {
	knex: Knex;
	accountability: Accountability | null;
	authorizationService: AuthorizationService;
	filesService: FilesService;

	constructor(options: AbstractServiceOptions) {
		this.knex = options.knex || getDatabase();
		this.accountability = options.accountability || null;
		this.filesService = new FilesService({ ...options, accountability: null });
		this.authorizationService = new AuthorizationService(options);
	}

	async getAsset(
		id: string,
		transformation?: TransformationSet,
		range?: Range,
	): Promise<{ stream: Readable; file: any; stat: Stat }> {
		const storage = await getStorage();