Skip to content

Commit

Permalink
feat: flagged nsfw project thumbnail
Browse files Browse the repository at this point in the history
  • Loading branch information
Asadaaaaa committed Aug 27, 2024
1 parent cc0a690 commit 69f21d2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/models/ProjectThumbnail.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ class ProjectThumbnail {
url: {
type: DataTypes.TEXT,
allowNull: true
},
flagged_nsfw: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false
}
}, {
tableName: 'project_thumbnail',
Expand Down
17 changes: 14 additions & 3 deletions src/services/primary/Project.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,8 @@ class ProjectService {
}

await transaction.commit();
const filteredArrayOfImages = [logo, thumbnail.data, image1, image2, image3].filter(item => item !== null);
this.nsfwDetector(filteredArrayOfImages, addDataProjectModel[0].dataValues.id);

this.nsfwDetector([thumbnail.data, image1, image2, image3], addDataProjectModel[0].dataValues.id);
} catch (err) {
console.log(err)
return -500;
Expand All @@ -394,6 +394,8 @@ class ProjectService {
async nsfwDetector(images, projectId) {
const url = 'https://api-fluxync.sersow.com/v1/primary/services/nsfw-detector/demo';
for (let i = 0; i < images.length; i++) {
if(images[i] === null) continue;

try {
const getNSFWDetectorData = await fetch(url, {
method: 'POST',
Expand All @@ -405,11 +407,18 @@ class ProjectService {
})
});
const getNSFWDetectorDataJson = await getNSFWDetectorData.json();
this.server.sendLogs(JSON.stringify(getNSFWDetectorDataJson, null, 2));

if(getNSFWDetectorDataJson.data.image_label === 'porn') {
await this.ProjectModel.update({ flagged_nsfw: true }, {
where: { id: projectId }
});

if(i === 0) {
await this.ProjectThumbnailModel.update({ flagged_nsfw: true }, {
where: { project_id: projectId }
});
}

break;
}
} catch (error) {
Expand Down Expand Up @@ -1342,6 +1351,8 @@ class ProjectService {
dataProjectModel[i].dataValues.thumbnail.isUrl = true;
dataProjectModel[i].dataValues.thumbnail.data = getDataProjectThumbnailModel.dataValues.url;
}

dataProjectModel[i].dataValues.thumbnail.flagged_nsfw = getDataProjectThumbnailModel.dataValues.flagged_nsfw;
} else {
dataProjectModel[i].dataValues.thumbnail = null;
}
Expand Down

0 comments on commit 69f21d2

Please sign in to comment.