Updated archivedMediaSchema to track channel by DB identifier instead of name.

This commit is contained in:
rainbow napkin 2026-07-06 01:06:55 -04:00
parent 0dda73cd14
commit a07edfc842
3 changed files with 11 additions and 10 deletions

View file

@ -777,7 +777,7 @@ class queue{
if(media == null){
try{
//Attempt to delete matching item from archived media
const deletedArchive = await archivedMediaModel.deleteOne({channel: this.channel.name, uuid: new BSON.UUID(uuid)});
const deletedArchive = await archivedMediaModel.deleteOne({channel: this.channel._id, uuid: new BSON.UUID(uuid)});
//if nothing got deleted
if(deletedArchive == null || deletedArchive.deletedCount == 0){
@ -1850,7 +1850,7 @@ class queue{
this.scheduleMedia([archivedMediaObject], null, chanDB, true, true, true);
//Splice the fucker out of the archive
await archivedMediaModel.deleteOne({channel: this.channel.name, uuid: new BSON.UUID(chanDB.media.liveRemainder)});
await archivedMediaModel.deleteOne({channel: this.channel._id, uuid: new BSON.UUID(chanDB.media.liveRemainder)});
}
//Break out of the loop
@ -1880,7 +1880,7 @@ class queue{
*/
async archiveMedia(media){
//Convert queuedMedia object to archivedMedia object
let archived = archivedMedia.fromQueuedMedia(media, this.channel.name);
let archived = archivedMedia.fromQueuedMedia(media, this.channel._id);
//Save archivedMedia object to site-wide media archive (gross but performant)
let archivedDoc = await archivedMediaModel.create(archived);
}
@ -1893,14 +1893,14 @@ class queue{
if(startDate != null){
//Return archived media after start date
return await archivedMediaModel.find({
channel:this.channel.name,
channel:this.channel._id,
//Prevent mongoose from attempting to sanatize and invalidate our query object, plus I think we can trust an epoch that came from server-side :)
startTime: mongoose.trusted({$gt: startDate.getTime()})
});
//Otherwise
}else{
//return all archived media
return await archivedMediaModel.find({channel:this.channel.name});
return await archivedMediaModel.find({channel:this.channel._id});
}
}
}

View file

@ -26,8 +26,9 @@ const archivedMedia = require('../../../app/channel/media/archivedMedia');
*/
const archivedProperties = new mongoose.Schema({
channel: {
type: mongoose.SchemaTypes.String,
required: true,
type: mongoose.SchemaTypes.ObjectID,
ref: "channel",
required: true
},
startTime: {
type: mongoose.SchemaTypes.Number,

View file

@ -23,7 +23,7 @@ const sessionUtils = require('./sessionUtils');
const statModel = require('../schemas/statSchema');
const { userModel } = require('../schemas/user/userSchema');
const channelModel = require('../schemas/channel/channelSchema');
const archiveModel = require('../schemas/channel/media/archivedMediaSchema');
const archivedMediaModel = require('../schemas/channel/media/archivedMediaSchema');
const { channelPlaylistModel } = require('../schemas/channel/media/playlist/playlistSchema');
const { userPlaylistModel } = require('../schemas/channel/media/playlist/playlistSchema');
const archivedMedia = require('../app/channel/media/archivedMedia');
@ -93,10 +93,10 @@ async function upgradePanamaRed(quiet = false){
const mediaObject = archivedMedia.fromQueuedMedia(entry.rehydrate())
//Tattoo channel name into media object
mediaObject.channel = channel.name;
mediaObject.channel = channel._id;
//Add media object to the site-wide media archive
await archiveModel.create(mediaObject);
await archivedMediaModel.create(mediaObject);
//We could just pull the archvied array count, but this feels more honest XP
archived++;