1 line
9.1 KiB
JavaScript
1 line
9.1 KiB
JavaScript
"use strict";exports.id=876,exports.ids=[876],exports.modules={6249:(t,e)=>{Object.defineProperty(e,"l",{enumerable:!0,get:function(){return function t(e,a){return a in e?e[a]:"then"in e&&"function"==typeof e.then?e.then(e=>t(e,a)):"function"==typeof e&&"default"===a?e:void 0}}})},432:(t,e,a)=>{a.d(e,{U:()=>n});var r=a(1450);let n={async getAllMaterials(t,e=1,a=20,n){let o=t?{type:t}:{};if(n&&n.trim()){let t=n.trim();o.OR=[{title:{contains:t,mode:"insensitive"}},{description:{contains:t,mode:"insensitive"}},{tags:{some:{name:{contains:t,mode:"insensitive"}}}}]}let[i,s]=await Promise.all([r.Z.material.findMany({where:o,include:{author:{select:{id:!0,username:!0,avatarUrl:!0,role:!0,status:!0,createdAt:!0,lastLogin:!0}},comments:{include:{author:{select:{id:!0,username:!0,role:!0,status:!0,createdAt:!0,lastLogin:!0,avatarUrl:!0}}},orderBy:{createdAt:"desc"}},favorites:!0,tags:!0},orderBy:{createdAt:"desc"},skip:(e-1)*a,take:a}),r.Z.material.count({where:o})]);return{items:i.map(t=>({id:t.id,title:t.title,description:t.description,type:t.type,contentUrl:t.contentUrl||void 0,codeSnippet:t.codeSnippet||void 0,language:t.language||void 0,author:{...t.author,role:t.author.role,createdAt:t.author.createdAt.toISOString(),lastLogin:t.author.lastLogin?.toISOString()||"",avatarUrl:t.author.avatarUrl||""},stats:{views:t.views,downloads:t.downloads,favorites:t.favorites.length},tags:t.tags.map(t=>t.name),createdAt:t.createdAt.toISOString(),comments:t.comments.map(t=>({id:t.id,content:t.content,createdAt:t.createdAt.toISOString(),author:{...t.author,role:t.author.role,createdAt:t.author.createdAt.toISOString(),lastLogin:t.author.lastLogin?.toISOString()||"",avatarUrl:t.author.avatarUrl||""}}))})),total:s}},async getMaterialsByAuthor(t,e=1,a=20){let[n,o]=await Promise.all([r.Z.material.findMany({where:{authorId:t},include:{author:{select:{id:!0,username:!0,avatarUrl:!0,role:!0,status:!0,createdAt:!0,lastLogin:!0}},comments:{include:{author:{select:{id:!0,username:!0,role:!0,status:!0,createdAt:!0,lastLogin:!0,avatarUrl:!0}}},orderBy:{createdAt:"desc"}},favorites:!0,tags:!0},orderBy:{createdAt:"desc"},skip:(e-1)*a,take:a}),r.Z.material.count({where:{authorId:t}})]);return{items:n.map(t=>({id:t.id,title:t.title,description:t.description,type:t.type,contentUrl:t.contentUrl||void 0,codeSnippet:t.codeSnippet||void 0,language:t.language||void 0,author:{...t.author,role:t.author.role,createdAt:t.author.createdAt.toISOString(),lastLogin:t.author.lastLogin?.toISOString()||"",avatarUrl:t.author.avatarUrl||""},stats:{views:t.views,downloads:t.downloads,favorites:t.favorites.length},tags:t.tags.map(t=>t.name),createdAt:t.createdAt.toISOString(),comments:t.comments.map(t=>({id:t.id,content:t.content,createdAt:t.createdAt.toISOString(),author:{...t.author,role:t.author.role,createdAt:t.author.createdAt.toISOString(),lastLogin:t.author.lastLogin?.toISOString()||"",avatarUrl:t.author.avatarUrl||""}}))})),total:o}},async getFavoritedMaterialsByUser(t,e=1,a=20){let[n,o]=await Promise.all([r.Z.material.findMany({where:{favorites:{some:{userId:t}}},include:{author:{select:{id:!0,username:!0,avatarUrl:!0,role:!0,status:!0,createdAt:!0,lastLogin:!0}},comments:{include:{author:{select:{id:!0,username:!0,role:!0,status:!0,createdAt:!0,lastLogin:!0,avatarUrl:!0}}},orderBy:{createdAt:"desc"}},favorites:!0,tags:!0},orderBy:{createdAt:"desc"},skip:(e-1)*a,take:a}),r.Z.material.count({where:{favorites:{some:{userId:t}}}})]);return{items:n.map(t=>({id:t.id,title:t.title,description:t.description,type:t.type,contentUrl:t.contentUrl||void 0,codeSnippet:t.codeSnippet||void 0,language:t.language||void 0,author:{...t.author,role:t.author.role,createdAt:t.author.createdAt.toISOString(),lastLogin:t.author.lastLogin?.toISOString()||"",avatarUrl:t.author.avatarUrl||""},stats:{views:t.views,downloads:t.downloads,favorites:t.favorites.length},tags:t.tags.map(t=>t.name),createdAt:t.createdAt.toISOString(),comments:t.comments.map(t=>({id:t.id,content:t.content,createdAt:t.createdAt.toISOString(),author:{...t.author,role:t.author.role,createdAt:t.author.createdAt.toISOString(),lastLogin:t.author.lastLogin?.toISOString()||"",avatarUrl:t.author.avatarUrl||""}}))})),total:o}},createMaterial:async(t,e)=>r.Z.material.create({data:{title:e.title,description:e.description,type:e.type,codeSnippet:e.codeSnippet,contentUrl:e.contentUrl,language:e.language||"text",authorId:t,tags:{connectOrCreate:e.tags.map(t=>({where:{name:t},create:{name:t}}))}}}),deleteMaterial:async t=>r.Z.material.delete({where:{id:t}}),incrementView:async t=>r.Z.material.update({where:{id:t},data:{views:{increment:1}}}),async getMaterialById(t){let e=await r.Z.material.findUnique({where:{id:t},include:{author:{select:{id:!0,username:!0,avatarUrl:!0,role:!0,status:!0,createdAt:!0,lastLogin:!0}},comments:{include:{author:{select:{id:!0,username:!0,role:!0,status:!0,createdAt:!0,lastLogin:!0,avatarUrl:!0}}},orderBy:{createdAt:"desc"}},favorites:!0,tags:!0}});return e?(await this.incrementView(t),{id:e.id,title:e.title,description:e.description,type:e.type,contentUrl:e.contentUrl||void 0,codeSnippet:e.codeSnippet||void 0,language:e.language||void 0,author:{...e.author,role:e.author.role,createdAt:e.author.createdAt.toISOString(),lastLogin:e.author.lastLogin?.toISOString()||"",avatarUrl:e.author.avatarUrl||""},stats:{views:e.views+1,downloads:e.downloads,favorites:e.favorites.length},tags:e.tags.map(t=>t.name),createdAt:e.createdAt.toISOString(),comments:e.comments.map(t=>({id:t.id,content:t.content,createdAt:t.createdAt.toISOString(),author:{...t.author,role:t.author.role,createdAt:t.author.createdAt.toISOString(),lastLogin:t.author.lastLogin?.toISOString()||"",avatarUrl:t.author.avatarUrl||""}}))}):null},addComment:async(t,e,a)=>r.Z.comment.create({data:{content:a,authorId:e,materialId:t},include:{author:{select:{id:!0,username:!0,avatarUrl:!0,role:!0,status:!0,createdAt:!0,lastLogin:!0}}}}),toggleFavorite:async(t,e)=>(await r.Z.favorite.findUnique({where:{userId_materialId:{userId:e,materialId:t}}})?await r.Z.favorite.delete({where:{userId_materialId:{userId:e,materialId:t}}}):await r.Z.favorite.create({data:{userId:e,materialId:t}}),await r.Z.favorite.count({where:{materialId:t}})),incrementDownload:async t=>r.Z.material.update({where:{id:t},data:{downloads:{increment:1}}})}},3481:(t,e,a)=>{a.d(e,{K:()=>o});var r=a(1450),n=a(1026);let o={async getUserById(t){let e=await r.Z.user.findUnique({where:{id:t},select:{id:!0,username:!0,avatarUrl:!0,role:!0,status:!0,createdAt:!0,lastLogin:!0}});return e?{...e,role:e.role,createdAt:e.createdAt.toISOString(),lastLogin:e.lastLogin?.toISOString()||new Date().toISOString(),avatarUrl:e.avatarUrl||""}:null},getUserByUsername:async t=>r.Z.user.findUnique({where:{username:t}}),async createUser(t,e,a){let o=await (0,n.c_)(e),i=`https://api.dicebear.com/7.x/avataaars/svg?seed=${t}`;return r.Z.user.create({data:{username:t,password:o,avatarUrl:i,role:"CREATOR",status:"ACTIVE"}})},async authenticateUser(t,e){let a=await this.getUserByUsername(t);return a&&a.password&&await (0,n.Gv)(e,a.password)?(await r.Z.user.update({where:{id:a.id},data:{lastLogin:new Date}}),{id:a.id,username:a.username,avatarUrl:a.avatarUrl||"",role:a.role,status:a.status,createdAt:a.createdAt.toISOString(),lastLogin:new Date().toISOString()}):null},getAllUsers:async()=>r.Z.user.findMany({orderBy:{createdAt:"desc"}}),updateUser:async(t,e)=>r.Z.user.update({where:{id:t},data:{username:e.username,avatarUrl:e.avatarUrl}}),updateUserRole:async(t,e)=>r.Z.user.update({where:{id:t},data:{role:e}}),async toggleUserStatus(t){let e=await r.Z.user.findUnique({where:{id:t}});if(!e)throw Error("User not found");let a="ACTIVE"===e.status?"BANNED":"ACTIVE";return r.Z.user.update({where:{id:t},data:{status:a}})}}},1026:(t,e,a)=>{a.d(e,{Gv:()=>l,RA:()=>c,WX:()=>u,c_:()=>d});var r=a(7096),n=a.n(r),o=a(9344),i=a.n(o);function s(){let t=process.env.JWT_SECRET;if(!t)throw Error("JWT_SECRET is not set");return t}async function d(t){return n().hash(t,10)}async function l(t,e){return n().compare(t,e)}function c(t){return i().sign({userId:t},s(),{expiresIn:"7d"})}function u(t){try{return i().verify(t,s())}catch(t){return null}}},8103:(t,e,a)=>{a.d(e,{R:()=>i,m:()=>o});var r=a(1026),n=a(3481);async function o(t,e){let a=s(t);if(!a)return e.status(401).json({success:!1,error:"Authentication required"}),!1;let o=(0,r.WX)(a);if(!o)return e.status(401).json({success:!1,error:"Invalid or expired token"}),!1;let i=await n.K.getUserById(o.userId);return i?"BANNED"===i.status?(e.status(403).json({success:!1,error:"Account has been banned"}),!1):(t.user=i,!0):(e.status(401).json({success:!1,error:"User not found"}),!1)}async function i(t){let e=s(t);if(!e)return;let a=(0,r.WX)(e);if(!a)return;let o=await n.K.getUserById(a.userId);o&&"BANNED"!==o.status&&(t.user=o)}function s(t){if(t.cookies.token)return t.cookies.token;let e=t.headers.authorization;return e&&e.startsWith("Bearer ")?e.substring(7):null}},1450:(t,e,a)=>{a.d(e,{Z:()=>n});var r=a(3524);let n=globalThis.prisma??new r.PrismaClient},7153:(t,e)=>{var a;Object.defineProperty(e,"x",{enumerable:!0,get:function(){return a}}),function(t){t.PAGES="PAGES",t.PAGES_API="PAGES_API",t.APP_PAGE="APP_PAGE",t.APP_ROUTE="APP_ROUTE"}(a||(a={}))},1802:(t,e,a)=>{t.exports=a(145)}}; |