Skip to content
This repository was archived by the owner on Sep 30, 2025. It is now read-only.
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
22 changes: 13 additions & 9 deletions src/app/models/thumbnail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Sequelize, ModelDefined, DataTypes } from 'sequelize';
export interface ThumbnailAttributes {
id: number;
file_id: number;
file_uuid: string;
type: string;
size: number;
bucket_id: string;
Expand All @@ -22,35 +23,38 @@ export default (database: Sequelize): ThumbnailModel => {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
allowNull: false
allowNull: false,
},
file_id: {
type: DataTypes.INTEGER,
allowNull: false
allowNull: false,
},
file_uuid: {
type: DataTypes.STRING,
},
max_width: {
type: DataTypes.INTEGER,
allowNull: false
allowNull: false,
},
max_height: {
type: DataTypes.INTEGER,
allowNull: false
allowNull: false,
},
type: {
type: DataTypes.STRING,
allowNull: false
allowNull: false,
},
size: {
type: DataTypes.BIGINT.UNSIGNED
type: DataTypes.BIGINT.UNSIGNED,
},
bucket_id: {
type: DataTypes.STRING(24)
type: DataTypes.STRING(24),
},
bucket_file: {
type: DataTypes.STRING(24)
type: DataTypes.STRING(24),
},
encrypt_version: {
type: DataTypes.STRING(20)
type: DataTypes.STRING(20),
},
created_at: {
type: DataTypes.VIRTUAL,
Expand Down
8 changes: 7 additions & 1 deletion src/app/routes/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,13 @@ export class StorageController {
return res.status(400).json({ error: 'Invalid metadata for new thumbnail' });
}

const result = await this.services.Thumbnails.CreateThumbnail(behalfUser, thumbnail);
const file = await this.services.Files.getFileByUserAndNumericId(behalfUser, thumbnail.file_id);
if (!file) {
this.logger.error(`File not found for thumbnail ${thumbnail.file_id}`);
return res.status(404).json({ error: 'File not found' });
}

const result = await this.services.Thumbnails.CreateThumbnail(behalfUser, thumbnail, file);

res.status(200).json(result);
}
Expand Down
12 changes: 12 additions & 0 deletions src/app/services/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
await file.destroy();
};

const UpdateMetadata = (user, fileId, metadata, mnemonic, bucketId, relativePath) => {

Check warning on line 168 in src/app/services/files.js

View workflow job for this annotation

GitHub Actions / build (16.x)

'relativePath' is defined but never used

Check warning on line 168 in src/app/services/files.js

View workflow job for this annotation

GitHub Actions / build (16.x)

'bucketId' is defined but never used

Check warning on line 168 in src/app/services/files.js

View workflow job for this annotation

GitHub Actions / build (16.x)

'mnemonic' is defined but never used

Check warning on line 168 in src/app/services/files.js

View workflow job for this annotation

GitHub Actions / run-tests (16.x)

'relativePath' is defined but never used

Check warning on line 168 in src/app/services/files.js

View workflow job for this annotation

GitHub Actions / run-tests (16.x)

'bucketId' is defined but never used

Check warning on line 168 in src/app/services/files.js

View workflow job for this annotation

GitHub Actions / run-tests (16.x)

'mnemonic' is defined but never used
const newMeta = {};

return async.waterfall([
Expand Down Expand Up @@ -350,6 +350,17 @@
});
};

const getFileByUserAndNumericId = async (user, numericId) => {
const file = await Model.file.findOne({
where: {
id: { [Op.eq]: numericId },
userId: { [Op.eq]: user.id },
},
});

return file;
};

const getRecentFiles = (user, limit) => {
return Model.file
.findAll({
Expand Down Expand Up @@ -406,5 +417,6 @@
getFileByFolder,
getByFolderAndUserId,
getFileByFileId,
getFileByUserAndNumericId,
};
};
21 changes: 9 additions & 12 deletions src/app/services/thumbnails.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ const sequelize = require('sequelize');
const { Op } = sequelize;

module.exports = (Model, App) => {
const CreateThumbnail = async (user, thumbnail) => {

const CreateThumbnail = async (user, thumbnail, file) => {
const thumbnailExists = await Model.thumbnail.findOne({
where: {
file_id: { [Op.eq]: thumbnail.file_id },
Expand All @@ -13,6 +12,7 @@ module.exports = (Model, App) => {

const thumbnailInfo = {
file_id: thumbnail.file_id,
file_uuid: file.uuid,
type: thumbnail.type,
max_width: thumbnail.max_width,
max_height: thumbnail.max_height,
Expand All @@ -27,17 +27,14 @@ module.exports = (Model, App) => {
if (thumbnailExists) {
thumbnailInfo.updated_at = new Date();
await App.services.Inxt.DeleteFile(user, thumbnailExists.bucket_id, thumbnailExists.bucket_file);
await Model.thumbnail.update(
thumbnailInfo,
{
where: {
file_id: { [Op.eq]: thumbnail.file_id },
max_width: { [Op.eq]: thumbnail.max_width },
max_height: { [Op.eq]: thumbnail.max_height },
type: { [Op.eq]: thumbnail.type },
}
await Model.thumbnail.update(thumbnailInfo, {
where: {
file_id: { [Op.eq]: thumbnail.file_id },
max_width: { [Op.eq]: thumbnail.max_width },
max_height: { [Op.eq]: thumbnail.max_height },
type: { [Op.eq]: thumbnail.type },
},
);
});
return await Model.thumbnail.findOne({
where: {
file_id: { [Op.eq]: thumbnail.file_id },
Expand Down
Loading