@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
2 lines • 2.89 kB
JavaScript
import{copy as e}from"../../../i18n/copy.mjs";import t from"../../../../constants/constants.mjs";import n from"../../../../utils/errors/lucid-api-error.mjs";import r from"../../utils/create-service-context.mjs";import i from"../../../../utils/services/service-wrapper.mjs";import a from"../../../../services/media-share-links/authorize-share.mjs";import o from"../../../../services/media-share-links/get-share-access.mjs";import s from"../../../../services/media-share-links/stream-media.mjs";import c from"../../middleware/rate-limiter.mjs";import l from"../../middleware/validate.mjs";import u from"../../openapi/index.mjs";import{controllerSchemas as d}from"../../../../schemas/share.mjs";import f from"../../../../utils/share-link/auth-cookie.mjs";import{applyRangeHeaders as p,applyStreamingHeaders as m,parseRangeHeader as h}from"../../utils/streaming.mjs";import{minutesToMilliseconds as g}from"date-fns";import{getCookie as _}from"hono/cookie";import{Readable as v}from"node:stream";import{createFactory as y}from"hono/factory";import{describeRoute as b}from"hono-openapi";import{stream as x}from"hono/streaming";const S=y().createHandlers(b({description:`Streams shared media content by token.`,tags:[`share`],summary:`Stream Shared Media`,parameters:u.parameters({params:d.streamShareMedia.params})}),c({mode:`ip`,scope:t.rateLimit.scopes.stream.scopeKey,limit:t.rateLimit.scopes.stream.limit,windowMs:g(1)}),l(`param`,d.streamShareMedia.params),l(`query`,d.streamShareMedia.query.string),async t=>{let{token:c}=t.req.valid(`param`),l=t.req.valid(`query`),u=r(t),d=h(t.req.header(`range`)),g=_(t,f(c)),y=await i(a,{transaction:!1})(u,{token:c,sessionCookie:g,enforcePasswordSession:!0});if(y.error)throw new n(y.error);let b=await i(o,{transaction:!1})(u,{token:c,sessionCookie:g});if(b.error)throw new n(b.error);if(b.data.passwordRequired)throw new n({type:`authorisation`,status:401,name:e(`server:core.share.stream.password.required.title`),message:e(`server:core.share.stream.password.required.message`)});if(!b.data.media.previewable)throw new n({type:`basic`,status:415,name:e(`server:core.share.stream.unsupported.media.type.name`),message:e(`server:core.share.stream.unsupported.media.type.message`)});let S=l.poster===`true`&&y.data.posterKey?y.data.posterKey:y.data.mediaKey,C=await i(s,{transaction:!1})(u,{mediaKey:S,range:d});if(C.error)throw new n(C.error);return p(t,{isPartial:C.data.isPartialContent,range:C.data.range,totalSize:C.data.totalSize}),m(t,{key:C.data.key,contentLength:C.data.contentLength,contentType:C.data.contentType,etag:C.data.etag??void 0}),x(t,async e=>{if(C.data.body instanceof ReadableStream)await e.pipe(C.data.body);else if(C.data.body instanceof Uint8Array)await e.write(C.data.body);else if(C.data.body instanceof v)for await(let t of C.data.body)await e.write(t)})});export{S as default};
//# sourceMappingURL=stream-media.mjs.map