UNPKG

@lucidcms/core

Version:

The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.

2 lines 1.22 kB
import e from"../../constants/constants.mjs";import t from"../../utils/helpers/get-base-url.mjs";import n from"../../libs/repositories/media-share-links.mjs";import r from"../../utils/share-link/generate-token.mjs";import i from"./helpers/assert-media-access.mjs";import a from"../../libs/formatters/media-share-links.mjs";import o from"../../libs/formatters/index.mjs";import{scrypt as s}from"@noble/hashes/scrypt.js";const c=async(c,l)=>{let u=await i(c,{mediaId:l.mediaId});if(u.error)return u;let d=new n(c.db.client,c.config.db),f=r(),p=l.password?Buffer.from(s(l.password,c.config.secrets.encryption,e.scrypt)).toString(`base64`):null,m=await d.createSingle({data:{media_id:l.mediaId,token:f,password:p,expires_at:o.normalizeDate(l.expiresAt)??void 0,name:l.name??null,description:l.description??null,created_at:new Date().toISOString(),updated_at:new Date().toISOString(),created_by:l.userId,updated_by:l.userId},returning:[`id`,`media_id`,`token`,`password`,`expires_at`,`name`,`description`,`created_at`,`updated_at`,`created_by`,`updated_by`],validation:{enabled:!0}});return m.error?m:{error:void 0,data:a.formatSingle({link:m.data,host:t(c)})}};export{c as default}; //# sourceMappingURL=create-single.mjs.map