added isOrphan method, #6455

This commit is contained in:
Julian Lam
2018-04-16 16:44:17 -04:00
parent 2e125293e6
commit 0f13ae3c87
2 changed files with 25 additions and 0 deletions

View File

@@ -49,6 +49,13 @@ module.exports = function (Posts) {
db.getSortedSetRange('post:' + pid + ':uploads', 0, -1, callback);
};
Posts.uploads.isOrphan = function (filePath, callback) {
// Returns bool indicating whether a file is still CURRENTLY included in any posts
db.sortedSetCard('upload:' + md5(filePath) + ':pids', function (err, length) {
callback(err, length === 0);
});
};
Posts.uploads.associate = function (pid, filePaths, callback) {
// Adds an upload to a post's sorted set of uploads
const now = Date.now();