mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-09 15:35:47 +01:00
added isOrphan method, #6455
This commit is contained in:
@@ -49,6 +49,13 @@ module.exports = function (Posts) {
|
|||||||
db.getSortedSetRange('post:' + pid + ':uploads', 0, -1, callback);
|
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) {
|
Posts.uploads.associate = function (pid, filePaths, callback) {
|
||||||
// Adds an upload to a post's sorted set of uploads
|
// Adds an upload to a post's sorted set of uploads
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
|
|||||||
@@ -941,6 +941,24 @@ describe('Post\'s', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('.isOrphan()', function () {
|
||||||
|
it('should return false if upload is not an orphan', function (done) {
|
||||||
|
posts.uploads.isOrphan('abracadabra.png', function (err, isOrphan) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert.equal(false, isOrphan);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true if upload is an orphan', function (done) {
|
||||||
|
posts.uploads.isOrphan('shazam.jpg', function (err, isOrphan) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert.equal(true, isOrphan);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('.associate()', function () {
|
describe('.associate()', function () {
|
||||||
it('should add an image to the post\'s maintained list of uploads', function (done) {
|
it('should add an image to the post\'s maintained list of uploads', function (done) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
|
|||||||
Reference in New Issue
Block a user