Skip to content
This repository was archived by the owner on Sep 30, 2025. It is now read-only.

Commit 965cb4e

Browse files
authored
Merge pull request #472 from internxt/feat/register-file-uuif-on-thumbnail-creation
feat(thumbnails): add file_uuid to thumbnail model and update CreateThumbnail logic
2 parents e5fffc6 + 696b301 commit 965cb4e

4 files changed

Lines changed: 41 additions & 22 deletions

File tree

src/app/models/thumbnail.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Sequelize, ModelDefined, DataTypes } from 'sequelize';
33
export interface ThumbnailAttributes {
44
id: number;
55
file_id: number;
6+
file_uuid: string;
67
type: string;
78
size: number;
89
bucket_id: string;
@@ -22,35 +23,38 @@ export default (database: Sequelize): ThumbnailModel => {
2223
type: DataTypes.INTEGER,
2324
primaryKey: true,
2425
autoIncrement: true,
25-
allowNull: false
26+
allowNull: false,
2627
},
2728
file_id: {
2829
type: DataTypes.INTEGER,
29-
allowNull: false
30+
allowNull: false,
31+
},
32+
file_uuid: {
33+
type: DataTypes.STRING,
3034
},
3135
max_width: {
3236
type: DataTypes.INTEGER,
33-
allowNull: false
37+
allowNull: false,
3438
},
3539
max_height: {
3640
type: DataTypes.INTEGER,
37-
allowNull: false
41+
allowNull: false,
3842
},
3943
type: {
4044
type: DataTypes.STRING,
41-
allowNull: false
45+
allowNull: false,
4246
},
4347
size: {
44-
type: DataTypes.BIGINT.UNSIGNED
48+
type: DataTypes.BIGINT.UNSIGNED,
4549
},
4650
bucket_id: {
47-
type: DataTypes.STRING(24)
51+
type: DataTypes.STRING(24),
4852
},
4953
bucket_file: {
50-
type: DataTypes.STRING(24)
54+
type: DataTypes.STRING(24),
5155
},
5256
encrypt_version: {
53-
type: DataTypes.STRING(20)
57+
type: DataTypes.STRING(20),
5458
},
5559
created_at: {
5660
type: DataTypes.VIRTUAL,

src/app/routes/storage.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,13 @@ export class StorageController {
803803
return res.status(400).json({ error: 'Invalid metadata for new thumbnail' });
804804
}
805805

806-
const result = await this.services.Thumbnails.CreateThumbnail(behalfUser, thumbnail);
806+
const file = await this.services.Files.getFileByUserAndNumericId(behalfUser, thumbnail.file_id);
807+
if (!file) {
808+
this.logger.error(`File not found for thumbnail ${thumbnail.file_id}`);
809+
return res.status(404).json({ error: 'File not found' });
810+
}
811+
812+
const result = await this.services.Thumbnails.CreateThumbnail(behalfUser, thumbnail, file);
807813

808814
res.status(200).json(result);
809815
}

src/app/services/files.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,17 @@ module.exports = (Model, App) => {
350350
});
351351
};
352352

353+
const getFileByUserAndNumericId = async (user, numericId) => {
354+
const file = await Model.file.findOne({
355+
where: {
356+
id: { [Op.eq]: numericId },
357+
userId: { [Op.eq]: user.id },
358+
},
359+
});
360+
361+
return file;
362+
};
363+
353364
const getRecentFiles = (user, limit) => {
354365
return Model.file
355366
.findAll({
@@ -406,5 +417,6 @@ module.exports = (Model, App) => {
406417
getFileByFolder,
407418
getByFolderAndUserId,
408419
getFileByFileId,
420+
getFileByUserAndNumericId,
409421
};
410422
};

src/app/services/thumbnails.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ const sequelize = require('sequelize');
22
const { Op } = sequelize;
33

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

1413
const thumbnailInfo = {
1514
file_id: thumbnail.file_id,
15+
file_uuid: file.uuid,
1616
type: thumbnail.type,
1717
max_width: thumbnail.max_width,
1818
max_height: thumbnail.max_height,
@@ -27,17 +27,14 @@ module.exports = (Model, App) => {
2727
if (thumbnailExists) {
2828
thumbnailInfo.updated_at = new Date();
2929
await App.services.Inxt.DeleteFile(user, thumbnailExists.bucket_id, thumbnailExists.bucket_file);
30-
await Model.thumbnail.update(
31-
thumbnailInfo,
32-
{
33-
where: {
34-
file_id: { [Op.eq]: thumbnail.file_id },
35-
max_width: { [Op.eq]: thumbnail.max_width },
36-
max_height: { [Op.eq]: thumbnail.max_height },
37-
type: { [Op.eq]: thumbnail.type },
38-
}
30+
await Model.thumbnail.update(thumbnailInfo, {
31+
where: {
32+
file_id: { [Op.eq]: thumbnail.file_id },
33+
max_width: { [Op.eq]: thumbnail.max_width },
34+
max_height: { [Op.eq]: thumbnail.max_height },
35+
type: { [Op.eq]: thumbnail.type },
3936
},
40-
);
37+
});
4138
return await Model.thumbnail.findOne({
4239
where: {
4340
file_id: { [Op.eq]: thumbnail.file_id },

0 commit comments

Comments
 (0)