Skip to content

Commit b6e51c5

Browse files
committed
fix: media upload location key and space endpoint resolution
1 parent dbb5d2c commit b6e51c5

File tree

118 files changed

+370
-469
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+370
-469
lines changed

compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ services:
1717
- reverseproxy
1818

1919
fra1.space.liexp.dev:
20-
image: minio/minio:latest
20+
image: minio/minio:RELEASE.2024-08-03T04-33-23Z
2121
command: server --console-address ":9001" /data
2222
ports:
2323
- "127.0.0.1:9000:9000"

lies.exposed.code-workspace

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"typescript.format.enable": true,
7070
"eslint.codeActionsOnSave.mode": "problems",
7171
"eslint.workingDirectories": [
72-
"./",
72+
"./"
7373
],
7474
"eslint.useFlatConfig": true,
7575
"explorer.fileNesting.enabled": true,

packages/@liexp/backend/src/flows/media/thumbnails/extractThumbnail.flow.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { fp, pipe } from "@liexp/core/lib/fp/index.js";
33
import { ImageType } from "@liexp/shared/lib/io/http/Media/index.js";
44
import { Media } from "@liexp/shared/lib/io/http/index.js";
55
import { getMediaThumbKey } from "@liexp/shared/lib/utils/media.utils.js";
6+
import { ensureHTTPProtocol } from "@liexp/shared/lib/utils/url.utils.js";
67
import { Schema } from "effect";
78
import { type ReaderTaskEither } from "fp-ts/lib/ReaderTaskEither.js";
89
import { type ConfigContext } from "../../../context/config.context.js";
@@ -16,7 +17,6 @@ import { type PDFProviderContext } from "../../../context/pdf.context.js";
1617
import { type PuppeteerProviderContext } from "../../../context/puppeteer.context.js";
1718
import { type ServerError } from "../../../errors/ServerError.js";
1819
import { type SimpleMedia } from "../../../io/media.io.js";
19-
import { LoggerService } from "../../../services/logger/logger.service.js";
2020
import { extractMP4Thumbnail } from "./extractMP4Thumbnail.flow.js";
2121
import { extractThumbnailFromImage } from "./extractThumbnailFromImage.flow.js";
2222
import { extractThumbnailFromPDF } from "./extractThumbnailFromPDF.flow.js";
@@ -37,17 +37,17 @@ export const extractThumbnail = <
3737
media: SimpleMedia,
3838
): ReaderTaskEither<C, ServerError, PutObjectCommandInput[]> => {
3939
return pipe(
40-
fp.RTE.right<C, ServerError, SimpleMedia>(media),
41-
LoggerService.RTE.debug((m) => [
42-
"Extracting thumbnail from url %s with type %s",
43-
m.location,
44-
m.type,
45-
]),
40+
fp.RTE.Do,
41+
fp.RTE.apS("media", fp.RTE.right(media)),
4642
fp.RTE.bind("bucket", () => fp.RTE.asks((ctx: C) => ctx.env.SPACE_BUCKET)),
43+
fp.RTE.apS("location", fp.RTE.right(ensureHTTPProtocol(media.location))),
4744
fp.RTE.bind(
4845
"thumbnails",
49-
(): ReaderTaskEither<C, ServerError, readonly ArrayBuffer[]> => {
50-
const { type, ...m } = media;
46+
({
47+
location,
48+
media,
49+
}): ReaderTaskEither<C, ServerError, readonly ArrayBuffer[]> => {
50+
const { type, ...m } = { ...media, location };
5151

5252
if (Schema.is(Media.PDFType)(type)) {
5353
return extractThumbnailFromPDF({
@@ -86,7 +86,7 @@ export const extractThumbnail = <
8686
fp.A.traverse(fp.RTE.ApplicativePar)(resizeThumbnailFlow<C>),
8787
);
8888
}),
89-
fp.RTE.map(({ resizedThumbnail, bucket }) => {
89+
fp.RTE.map(({ resizedThumbnail, bucket, media }) => {
9090
return resizedThumbnail.map((Body, index) => ({
9191
Key: getMediaThumbKey(
9292
media.id,

packages/@liexp/backend/src/flows/media/thumbnails/extractThumbnailFromPDF.flow.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ export const extractThumbnailFromPDFPage = (
3838
? [outputScale, 0, 0, outputScale, 0, 0]
3939
: undefined;
4040

41-
const renderContext: RenderParameters = {
41+
const renderContext = {
4242
canvasContext: context as unknown as CanvasRenderingContext2D,
4343
transform,
4444
viewport,
45-
};
45+
} as RenderParameters;
4646

4747
await page.render(renderContext).promise;
4848

packages/@liexp/backend/src/flows/tg/parseDocument.flow.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export const parseDocument =
6666

6767
return createAndUpload(
6868
{
69+
id: mediaId,
6970
type: contentType,
7071
location: messageDocument.file_id as URL,
7172
label: messageDocument.file_name,

packages/@liexp/backend/src/flows/tg/parsePhoto.flow.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export const parsePhoto =
5656

5757
return createAndUpload(
5858
{
59+
id: mediaId,
5960
type: MediaType.members[0].literals[0],
6061
location: p.file_id as URL,
6162
label: description,

packages/@liexp/backend/src/flows/tg/parseVideo.flow.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { pipe } from "@liexp/core/lib/fp/index.js";
22
import { type URL } from "@liexp/shared/lib/io/http/Common/URL.js";
33
import { uuid, type UUID } from "@liexp/shared/lib/io/http/Common/UUID.js";
44
import { MP4Type } from "@liexp/shared/lib/io/http/Media/index.js";
5-
import { ensureHTTPS } from "@liexp/shared/lib/utils/url.utils.js";
5+
import { getMediaKey } from "@liexp/shared/lib/utils/media.utils.js";
6+
import { ensureHTTPProtocol } from "@liexp/shared/lib/utils/url.utils.js";
67
import { sequenceS } from "fp-ts/lib/Apply.js";
78
import * as O from "fp-ts/lib/Option.js";
89
import { type ReaderTaskEither } from "fp-ts/lib/ReaderTaskEither.js";
@@ -67,13 +68,13 @@ export const parseVideo =
6768
TE.chain((f) => {
6869
return pipe(
6970
upload({
70-
Key: `public/media/${mediaId}/${mediaId}.jpg`,
71+
Key: getMediaKey("media", mediaId, mediaId, "image/jpeg"),
7172
Body: f,
7273
})(ctx),
7374
TE.mapLeft(ServerError.fromUnknown),
7475
);
7576
}),
76-
TE.map((r) => ensureHTTPS(r.Location)),
77+
TE.map((r) => ensureHTTPProtocol(r.Location)),
7778
),
7879
),
7980
);
@@ -89,6 +90,7 @@ export const parseVideo =
8990
TE.chain(({ video, thumb }) => {
9091
return createAndUpload(
9192
{
93+
id: mediaId,
9294
type: MP4Type.literals[0],
9395
location: "" as URL,
9496
label: description,

packages/@liexp/backend/src/io/Actor.io.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ import { type ActorEntity } from "../entities/Actor.entity.js";
1414
import { IOCodec } from "./DomainCodec.js";
1515
import { MediaIO } from "./media.io.js";
1616

17-
export const encodeActor = (
18-
{ old_avatar, ...a }: ActorEntity,
19-
spaceEndpoint: string,
20-
): E.Either<
17+
export const encodeActor = ({
18+
old_avatar,
19+
...a
20+
}: ActorEntity): E.Either<
2121
_DecodeError,
2222
Schema.Schema.Encoded<typeof io.http.Actor.Actor>
2323
> => {
@@ -30,7 +30,7 @@ export const encodeActor = (
3030
? Schema.is(UUID)(a.avatar)
3131
? E.right(a.avatar)
3232
: pipe(
33-
MediaIO.decodeSingle(a.avatar, spaceEndpoint),
33+
MediaIO.decodeSingle(a.avatar),
3434
// E.map((m) => ({
3535
// ...m,
3636
// createdAt: m.createdAt.toISOString(),
@@ -61,10 +61,10 @@ export const encodeActor = (
6161
);
6262
};
6363

64-
const decodeActor = (
65-
{ old_avatar, ...a }: ActorEntity,
66-
spaceEndpoint: string,
67-
): E.Either<_DecodeError, io.http.Actor.Actor> => {
64+
const decodeActor = ({
65+
old_avatar,
66+
...a
67+
}: ActorEntity): E.Either<_DecodeError, io.http.Actor.Actor> => {
6868
return pipe(
6969
E.Do,
7070
E.bind(
@@ -76,7 +76,7 @@ const decodeActor = (
7676
a.avatar
7777
? Schema.is(UUID)(a.avatar)
7878
? E.right(a.avatar)
79-
: pipe(MediaIO.encodeSingle(a.avatar, spaceEndpoint))
79+
: pipe(MediaIO.encodeSingle(a.avatar))
8080
: E.right(undefined),
8181
),
8282
E.chain(({ avatar }) => {

packages/@liexp/backend/src/io/Area.io.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import { type AreaEntity } from "../entities/Area.entity.js";
1212
import { IOCodec } from "./DomainCodec.js";
1313
import { MediaIO } from "./media.io.js";
1414

15-
const toAreaIO = (
16-
{ featuredImage, ...area }: AreaEntity,
17-
spaceEndpoint: string,
18-
): E.Either<_DecodeError, io.http.Area.Area> => {
15+
const toAreaIO = ({
16+
featuredImage,
17+
...area
18+
}: AreaEntity): E.Either<_DecodeError, io.http.Area.Area> => {
1919
return pipe(
2020
featuredImage
21-
? MediaIO.decodeSingle(featuredImage, spaceEndpoint)
21+
? MediaIO.decodeSingle(featuredImage)
2222
: E.right<_DecodeError, io.http.Media.Media | null>(null),
2323
fp.E.chain((media) =>
2424
pipe(

packages/@liexp/backend/src/io/group.io.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ import { type GroupEntity } from "../entities/Group.entity.js";
1414
import { IOCodec } from "./DomainCodec.js";
1515
import { MediaIO } from "./media.io.js";
1616

17-
const encodeGroupIO = (
18-
{ avatar, old_avatar, ...group }: GroupEntity,
19-
spaceEndpoint: string,
20-
): E.Either<
17+
const encodeGroupIO = ({
18+
avatar,
19+
old_avatar,
20+
...group
21+
}: GroupEntity): E.Either<
2122
_DecodeError,
2223
Schema.Schema.Encoded<typeof io.http.Group.Group>
2324
> => {
@@ -26,9 +27,7 @@ const encodeGroupIO = (
2627
E.bind(
2728
"avatar",
2829
(): E.Either<_DecodeError, io.http.Media.Media | undefined> =>
29-
avatar
30-
? pipe(MediaIO.decodeSingle(avatar, spaceEndpoint))
31-
: E.right(undefined),
30+
avatar ? pipe(MediaIO.decodeSingle(avatar)) : E.right(undefined),
3231
),
3332
E.map(({ avatar }) => ({
3433
...group,
@@ -57,10 +56,11 @@ const encodeGroupIO = (
5756
),
5857
);
5958
};
60-
const decodeGroupIO = (
61-
{ avatar, old_avatar, ...group }: GroupEntity,
62-
spaceEndpoint: string,
63-
): E.Either<_DecodeError, io.http.Group.Group> => {
59+
const decodeGroupIO = ({
60+
avatar,
61+
old_avatar,
62+
...group
63+
}: GroupEntity): E.Either<_DecodeError, io.http.Group.Group> => {
6464
return pipe(
6565
E.Do,
6666
E.bind(
@@ -72,7 +72,7 @@ const decodeGroupIO = (
7272
avatar
7373
? Schema.is(UUID)(avatar)
7474
? E.right(avatar)
75-
: pipe(MediaIO.encodeSingle(avatar, spaceEndpoint))
75+
: pipe(MediaIO.encodeSingle(avatar))
7676
: E.right(undefined),
7777
),
7878
E.chain(({ avatar }) =>

0 commit comments

Comments
 (0)