Updated removeMedia() function to remove archived media from site-wide media archive.
This commit is contained in:
parent
ae294b3f78
commit
ee47e1b844
1 changed files with 6 additions and 29 deletions
|
|
@ -17,6 +17,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
||||||
//NPM imports
|
//NPM imports
|
||||||
const validator = require('validator');
|
const validator = require('validator');
|
||||||
const mongoose = require('mongoose');
|
const mongoose = require('mongoose');
|
||||||
|
const { BSON } = require('mongodb');
|
||||||
|
|
||||||
//Local imports
|
//Local imports
|
||||||
const config = require('../../../../config.json');
|
const config = require('../../../../config.json');
|
||||||
|
|
@ -775,29 +776,11 @@ class queue{
|
||||||
//If we couldn't find anything in the current channel schedule
|
//If we couldn't find anything in the current channel schedule
|
||||||
if(media == null){
|
if(media == null){
|
||||||
try{
|
try{
|
||||||
//If we wheren't handed a channel
|
//Attempt to delete matching item from archived media
|
||||||
if(chanDB == null){
|
const deletedArchive = await archivedMediaModel.deleteOne({channel: this.channel.name, uuid: new BSON.UUID(uuid)});
|
||||||
//DO everything ourselves since we don't have a fance end() function to do it
|
|
||||||
chanDB = await channelModel.findOne({name:this.channel.name});
|
|
||||||
}
|
|
||||||
|
|
||||||
//If we couldn't find the channel
|
//if nothing got deleted
|
||||||
if(chanDB == null){
|
if(deletedArchive == null || deletedArchive.deletedCount == 0){
|
||||||
//FUCK
|
|
||||||
throw loggerUtils.exceptionSmith(`Unable to find channel document ${this.channel.name} while queue item!`, "queue");
|
|
||||||
}
|
|
||||||
|
|
||||||
//Keep a copy of the archive that hasn't been changed
|
|
||||||
const preArchive = await this.getArchive();
|
|
||||||
|
|
||||||
//This logic wont work since we cant just set the archive as an array anymore, maybe using mongoose.delete finding by channel and uuid?
|
|
||||||
//Filter out the requested item from the archive
|
|
||||||
/*chanDB.media.archived = chanDB.media.archived.filter((record)=>{
|
|
||||||
return record.uuid.toString() != uuid;
|
|
||||||
})*/
|
|
||||||
|
|
||||||
//If nothing changed in the archive
|
|
||||||
if(preArchive.length == chanDB.media.archived.length){
|
|
||||||
//If an originating socket was provided for this request
|
//If an originating socket was provided for this request
|
||||||
if(socket != null){
|
if(socket != null){
|
||||||
//Yell at the user for being an asshole
|
//Yell at the user for being an asshole
|
||||||
|
|
@ -808,13 +791,7 @@ class queue{
|
||||||
//If broadcasting is enabled
|
//If broadcasting is enabled
|
||||||
if(!noBroadcast){
|
if(!noBroadcast){
|
||||||
//Broadcast changes
|
//Broadcast changes
|
||||||
this.broadcastQueue(chanDB);
|
this.broadcastQueue();
|
||||||
}
|
|
||||||
|
|
||||||
//If saving is disabled
|
|
||||||
if(!noScheduling){
|
|
||||||
//Save changes to the DB
|
|
||||||
await chanDB.save();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}catch(err){
|
}catch(err){
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue