mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-20 10:20:15 +01:00
refactor: original changes
This commit is contained in:
parent
fa9177180f
commit
f9c0e9853f
83 changed files with 413 additions and 505 deletions
|
|
@ -1,8 +1,7 @@
|
|||
const { nanoid } = require('nanoid');
|
||||
const { Constants } = require('librechat-data-provider');
|
||||
const db = require('~/lib/db/connectDb');
|
||||
const { SharedLink, Conversation, logger } = require('@librechat/data-schemas');
|
||||
const { getMessages } = require('./Message');
|
||||
const logger = require('~/config/winston');
|
||||
|
||||
class ShareServiceError extends Error {
|
||||
constructor(message, code) {
|
||||
|
|
@ -73,7 +72,7 @@ function anonymizeMessages(messages, newConvoId) {
|
|||
|
||||
async function getSharedMessages(shareId) {
|
||||
try {
|
||||
const share = await db.models.SharedLink.findOne({ shareId, isPublic: true })
|
||||
const share = await SharedLink.findOne({ shareId, isPublic: true })
|
||||
.populate({
|
||||
path: 'messages',
|
||||
select: '-_id -__v -user',
|
||||
|
|
@ -148,7 +147,7 @@ async function getSharedLinks(user, pageParam, pageSize, isPublic, sortBy, sortD
|
|||
query.conversationId = { $in: query.conversationId };
|
||||
}
|
||||
|
||||
const sharedLinks = await db.models.SharedLink.find(query)
|
||||
const sharedLinks = await SharedLink.find(query)
|
||||
.sort(sort)
|
||||
.limit(pageSize + 1)
|
||||
.select('-__v -user')
|
||||
|
|
@ -181,7 +180,7 @@ async function getSharedLinks(user, pageParam, pageSize, isPublic, sortBy, sortD
|
|||
|
||||
async function deleteAllSharedLinks(user) {
|
||||
try {
|
||||
const result = await db.models.SharedLink.deleteMany({ user });
|
||||
const result = await SharedLink.deleteMany({ user });
|
||||
return {
|
||||
message: 'All shared links deleted successfully',
|
||||
deletedCount: result.deletedCount,
|
||||
|
|
@ -199,7 +198,6 @@ async function createSharedLink(user, conversationId) {
|
|||
if (!user || !conversationId) {
|
||||
throw new ShareServiceError('Missing required parameters', 'INVALID_PARAMS');
|
||||
}
|
||||
const { SharedLink, Conversation } = db.models;
|
||||
try {
|
||||
const [existingShare, conversationMessages] = await Promise.all([
|
||||
SharedLink.findOne({ conversationId, isPublic: true }).select('-_id -__v -user').lean(),
|
||||
|
|
@ -241,7 +239,7 @@ async function getSharedLink(user, conversationId) {
|
|||
}
|
||||
|
||||
try {
|
||||
const share = await db.models.SharedLink.findOne({ conversationId, user, isPublic: true })
|
||||
const share = await SharedLink.findOne({ conversationId, user, isPublic: true })
|
||||
.select('shareId -_id')
|
||||
.lean();
|
||||
|
||||
|
|
@ -265,7 +263,6 @@ async function updateSharedLink(user, shareId) {
|
|||
throw new ShareServiceError('Missing required parameters', 'INVALID_PARAMS');
|
||||
}
|
||||
|
||||
const { SharedLink } = db.models;
|
||||
try {
|
||||
const share = await SharedLink.findOne({ shareId }).select('-_id -__v -user').lean();
|
||||
|
||||
|
|
@ -316,7 +313,7 @@ async function deleteSharedLink(user, shareId) {
|
|||
}
|
||||
|
||||
try {
|
||||
const result = await db.models.SharedLink.findOneAndDelete({ shareId, user }).lean();
|
||||
const result = await SharedLink.findOneAndDelete({ shareId, user }).lean();
|
||||
|
||||
if (!result) {
|
||||
return null;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue