Skip to content

Commit

Permalink
feat: nsfw detector use fluxync
Browse files Browse the repository at this point in the history
  • Loading branch information
Asadaaaaa committed Aug 27, 2024
1 parent 5fb948d commit cc0a690
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/models/Project.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class Project {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false
},
flagged_nsfw: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false
}
}, {
tableName: 'project',
Expand Down
34 changes: 33 additions & 1 deletion src/services/primary/Project.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +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);
} catch (err) {
console.log(err)
return -500;
Expand All @@ -389,6 +391,35 @@ class ProjectService {
return 1;
}

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++) {
try {
const getNSFWDetectorData = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
image: images[i]
})
});
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 }
});
break;
}
} catch (error) {
continue;
}
}

return;
}

// Draft Project Function Service
async draftProject(reqData, userId) {
const getManageProject = await this.manageProject(reqData, false, userId);
Expand Down Expand Up @@ -586,7 +617,8 @@ class ProjectService {
'description',
['logo_path', 'logo'],
'published',
'published_datetime'
'published_datetime',
'flagged_nsfw'
]
});

Expand Down

0 comments on commit cc0a690

Please sign in to comment.