Skip to content

Commit

Permalink
fix(backend): create ffmpeg context
Browse files Browse the repository at this point in the history
  • Loading branch information
ascariandrea committed Jan 24, 2025
1 parent 90b2c1f commit 4a15253
Show file tree
Hide file tree
Showing 23 changed files with 48 additions and 60 deletions.
1 change: 1 addition & 0 deletions packages/@liexp/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"lib"
],
"scripts": {
"typecheck": "tsc",
"build": "tsc -b tsconfig.build.json",
"clean": "rm -rf lib",
"lint": "eslint src",
Expand Down
5 changes: 5 additions & 0 deletions packages/@liexp/backend/src/context/ffmpeg.context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { FFMPEGProvider } from "../providers/ffmpeg/ffmpeg.provider.js";

export interface FFMPEGProviderContext {
ffmpeg: FFMPEGProvider;
}
5 changes: 0 additions & 5 deletions packages/@liexp/backend/src/context/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { type FFMPEGProvider } from "../providers/ffmpeg/ffmpeg.provider.js";
import { type GeocodeProvider } from "../providers/geocode/geocode.provider.js";
import { type IGProvider } from "../providers/ig/ig.provider.js";
import { type ImgProcClient } from "../providers/imgproc/imgproc.provider.js";
import { type NERProvider } from "../providers/ner/ner.provider.js";
import { type TGBotProvider } from "../providers/tg/tg.provider.js";
import { type WikipediaProvider } from "../providers/wikipedia/wikipedia.provider.js";

export interface FFMPEGProviderContext {
ffmpeg: FFMPEGProvider;
}

export interface GeocodeProviderContext {
geo: GeocodeProvider;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { describe, expect, it, vi } from "vitest";
import { mock } from "vitest-mock-extended";
import { LinkEntity } from "../../entities/Link.entity.js";
import { UserEntity } from "../../entities/User.entity.js";
import { initContext, testConfig } from "../../test/index.js";
import { testConfig } from "../../test/index.js";
import { mockedContext, mockTERightOnce } from "../../test/mocks/mock.utils.js";
import { mocks } from "../../test/mocks.js";
import {
Expand Down
38 changes: 20 additions & 18 deletions packages/@liexp/backend/src/flows/media/createAndUpload.flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ import { type ReaderTaskEither } from "fp-ts/lib/ReaderTaskEither.js";
import { type ConfigContext } from "../../context/config.context.js";
import { type DatabaseContext } from "../../context/db.context.js";
import { type ENVContext } from "../../context/env.context.js";
import { type FFMPEGProviderContext } from "../../context/ffmpeg.context.js";
import { type FSClientContext } from "../../context/fs.context.js";
import { type HTTPProviderContext } from "../../context/http.context.js";
import {
type FFMPEGProviderContext,
type ImgProcClientContext,
} from "../../context/index.js";
import { type ImgProcClientContext } from "../../context/index.js";
import { type LoggerContext } from "../../context/logger.context.js";
import { type PDFProviderContext } from "../../context/pdf.context.js";
import { type PuppeteerProviderContext } from "../../context/puppeteer.context.js";
Expand All @@ -31,22 +29,23 @@ import { type MediaEntity } from "../../entities/Media.entity.js";
import { ServerError } from "../../errors/ServerError.js";
import { upload } from "../../flows/space/upload.flow.js";
import { MediaRepository } from "../../services/entity-repository.service.js";
import { LoggerService } from "../../services/logger/logger.service.js";
import { createThumbnail } from "./thumbnails/createThumbnail.flow.js";

export const createAndUpload = <
C extends SpaceContext &
ENVContext &
QueuesProviderContext &
DatabaseContext &
LoggerContext &
ConfigContext &
FSClientContext &
HTTPProviderContext &
PDFProviderContext &
FFMPEGProviderContext &
PuppeteerProviderContext &
ImgProcClientContext,
>(
export type CreateAndUploadFlowContext = SpaceContext &
ENVContext &
QueuesProviderContext &
DatabaseContext &
LoggerContext &
ConfigContext &
FSClientContext &
HTTPProviderContext &
PDFProviderContext &
FFMPEGProviderContext &
PuppeteerProviderContext &
ImgProcClientContext;

export const createAndUpload = <C extends CreateAndUploadFlowContext>(
createMediaData: Media.CreateMedia,
{ Body, ContentType }: { Body: any; ContentType?: MediaType },
id: UUID | undefined,
Expand All @@ -61,6 +60,7 @@ export const createAndUpload = <
if (IframeVideoType.is(createMediaData.type)) {
return fp.RTE.right(createMediaData.location);
}

const mediaKey = getMediaKey(
"media",
mediaId,
Expand All @@ -79,6 +79,7 @@ export const createAndUpload = <
);
}),
// ctx.logger.debug.logInTaskEither("Result %O"),
LoggerService.RTE.info("Result %O"),
fp.RTE.bind("thumbnail", ({ mediaId, location }) =>
pipe(
extractThumb
Expand All @@ -98,6 +99,7 @@ export const createAndUpload = <
MediaRepository.save<C>([
{
...createMediaData,
description: createMediaData.description ?? createMediaData.label,
events: [],
links: [],
featuredInStories: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
import type Ffmpeg from "fluent-ffmpeg";
import { type ReaderTaskEither } from "fp-ts/lib/ReaderTaskEither.js";
import { type ConfigContext } from "../../../context/config.context.js";
import { type FFMPEGProviderContext } from "../../../context/ffmpeg.context.js";
import { type FSClientContext } from "../../../context/fs.context.js";
import { type HTTPProviderContext } from "../../../context/http.context.js";
import { type FFMPEGProviderContext } from "../../../context/index.js";
import { type LoggerContext } from "../../../context/logger.context.js";
import { ServerError } from "../../../errors/ServerError.js";
import { downloadMP4Video } from "../downloadMP4Video.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ import {
import { type ReaderTaskEither } from "fp-ts/lib/ReaderTaskEither.js";
import { type ConfigContext } from "../../../context/config.context.js";
import { type ENVContext } from "../../../context/env.context.js";
import { type FFMPEGProviderContext } from "../../../context/ffmpeg.context.js";
import { type FSClientContext } from "../../../context/fs.context.js";
import { type HTTPProviderContext } from "../../../context/http.context.js";
import {
type ImgProcClientContext,
type FFMPEGProviderContext,
} from "../../../context/index.js";
import { type ImgProcClientContext } from "../../../context/index.js";
import { type LoggerContext } from "../../../context/logger.context.js";
import { type SpaceContext } from "../../../context/space.context.js";
import { type MediaEntity } from "../../../entities/Media.entity.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import { fp, pipe } from "@liexp/core/lib/fp/index.js";
import { type ReaderTaskEither } from "fp-ts/lib/ReaderTaskEither.js";
import { type ConfigContext } from "../../../context/config.context.js";
import { type ENVContext } from "../../../context/env.context.js";
import { type FFMPEGProviderContext } from "../../../context/ffmpeg.context.js";
import { type FSClientContext } from "../../../context/fs.context.js";
import { type HTTPProviderContext } from "../../../context/http.context.js";
import {
type FFMPEGProviderContext,
type ImgProcClientContext,
} from "../../../context/index.js";
import { type ImgProcClientContext } from "../../../context/index.js";
import { type LoggerContext } from "../../../context/logger.context.js";
import { type PDFProviderContext } from "../../../context/pdf.context.js";
import { type PuppeteerProviderContext } from "../../../context/puppeteer.context.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import type Ffmpeg from "fluent-ffmpeg";
import { type ReaderTaskEither } from "fp-ts/lib/ReaderTaskEither.js";
import * as TE from "fp-ts/lib/TaskEither.js";
import { type ConfigContext } from "../../../context/config.context.js";
import { type FFMPEGProviderContext } from "../../../context/ffmpeg.context.js";
import { type FSClientContext } from "../../../context/fs.context.js";
import { type HTTPProviderContext } from "../../../context/http.context.js";
import { type FFMPEGProviderContext } from "../../../context/index.js";
import { type LoggerContext } from "../../../context/logger.context.js";
import { ServerError } from "../../../errors/ServerError.js";
import { type SimpleMedia } from "../../../io/media.io.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import { getMediaThumbKey } from "@liexp/shared/lib/utils/media.utils.js";
import { type ReaderTaskEither } from "fp-ts/lib/ReaderTaskEither.js";
import { type ConfigContext } from "../../../context/config.context.js";
import { type ENVContext } from "../../../context/env.context.js";
import { type FFMPEGProviderContext } from "../../../context/ffmpeg.context.js";
import { type FSClientContext } from "../../../context/fs.context.js";
import { type HTTPProviderContext } from "../../../context/http.context.js";
import {
type ImgProcClientContext,
type FFMPEGProviderContext,
} from "../../../context/index.js";
import { type ImgProcClientContext } from "../../../context/index.js";
import { type LoggerContext } from "../../../context/logger.context.js";
import { type PDFProviderContext } from "../../../context/pdf.context.js";
import { type PuppeteerProviderContext } from "../../../context/puppeteer.context.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import { Equal } from "typeorm";
import { type ConfigContext } from "../../../context/config.context.js";
import { type DatabaseContext } from "../../../context/db.context.js";
import { type ENVContext } from "../../../context/env.context.js";
import { type FFMPEGProviderContext } from "../../../context/ffmpeg.context";
import { type FSClientContext } from "../../../context/fs.context.js";
import { type HTTPProviderContext } from "../../../context/http.context.js";
import {
type ImgProcClientContext,
type FFMPEGProviderContext,
} from "../../../context/index.js";
import { type ImgProcClientContext } from "../../../context/index.js";
import { type LoggerContext } from "../../../context/logger.context.js";
import { type PDFProviderContext } from "../../../context/pdf.context.js";
import { type PuppeteerProviderContext } from "../../../context/puppeteer.context.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import type * as puppeteer from "puppeteer-core";
import { type ConfigContext } from "../../../context/config.context.js";
import { type DatabaseContext } from "../../../context/db.context.js";
import { type ENVContext } from "../../../context/env.context.js";
import { type FFMPEGProviderContext } from "../../../context/ffmpeg.context.js";
import { type FSClientContext } from "../../../context/fs.context.js";
import { type HTTPProviderContext } from "../../../context/http.context.js";
import {
type TGBotProviderContext,
type FFMPEGProviderContext,
type ImgProcClientContext,
} from "../../../context/index.js";
import { type LoggerContext } from "../../../context/logger.context.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import type TelegramBot from "node-telegram-bot-api";
import { type ConfigContext } from "../../context/config.context.js";
import { type DatabaseContext } from "../../context/db.context.js";
import { type ENVContext } from "../../context/env.context.js";
import { type FFMPEGProviderContext } from "../../context/ffmpeg.context.js";
import { type FSClientContext } from "../../context/fs.context.js";
import { type HTTPProviderContext } from "../../context/http.context.js";
import {
type ImgProcClientContext,
type TGBotProviderContext,
type FFMPEGProviderContext,
} from "../../context/index.js";
import { type LoggerContext } from "../../context/logger.context.js";
import { type PDFProviderContext } from "../../context/pdf.context.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/@liexp/backend/src/flows/tg/parseDocument.flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import type TelegramBot from "node-telegram-bot-api";
import { type ConfigContext } from "../../context/config.context.js";
import { type DatabaseContext } from "../../context/db.context.js";
import { type ENVContext } from "../../context/env.context.js";
import { type FFMPEGProviderContext } from "../../context/ffmpeg.context.js";
import { type FSClientContext } from "../../context/fs.context.js";
import { type HTTPProviderContext } from "../../context/http.context.js";
import {
type ImgProcClientContext,
type FFMPEGProviderContext,
type TGBotProviderContext,
} from "../../context/index.js";
import { type LoggerContext } from "../../context/logger.context.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/@liexp/backend/src/flows/tg/parseMessages.flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { type ReaderTaskEither } from "fp-ts/lib/ReaderTaskEither.js";
import { type ConfigContext } from "../../context/config.context.js";
import { type DatabaseContext } from "../../context/db.context.js";
import { type ENVContext } from "../../context/env.context.js";
import { type FFMPEGProviderContext } from "../../context/ffmpeg.context.js";
import { type FSClientContext } from "../../context/fs.context.js";
import { type HTTPProviderContext } from "../../context/http.context.js";
import {
type ImgProcClientContext,
type TGBotProviderContext,
type FFMPEGProviderContext,
} from "../../context/index.js";
import { type LoggerContext } from "../../context/logger.context.js";
import { type PDFProviderContext } from "../../context/pdf.context.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/@liexp/backend/src/flows/tg/parsePhoto.flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import type TelegramBot from "node-telegram-bot-api";
import { type ConfigContext } from "../../context/config.context.js";
import { type DatabaseContext } from "../../context/db.context.js";
import { type ENVContext } from "../../context/env.context.js";
import { type FFMPEGProviderContext } from "../../context/ffmpeg.context.js";
import { type FSClientContext } from "../../context/fs.context.js";
import { type HTTPProviderContext } from "../../context/http.context.js";
import {
type ImgProcClientContext,
type FFMPEGProviderContext,
type TGBotProviderContext,
} from "../../context/index.js";
import { type LoggerContext } from "../../context/logger.context.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ import type * as puppeteer from "puppeteer-core";
import { type ConfigContext } from "../../context/config.context.js";
import { type DatabaseContext } from "../../context/db.context.js";
import { type ENVContext } from "../../context/env.context.js";
import { type FFMPEGProviderContext } from "../../context/ffmpeg.context.js";
import { type FSClientContext } from "../../context/fs.context.js";
import { type HTTPProviderContext } from "../../context/http.context.js";
import {
type ImgProcClientContext,
type FFMPEGProviderContext,
} from "../../context/index.js";
import { type ImgProcClientContext } from "../../context/index.js";
import { type LoggerContext } from "../../context/logger.context.js";
import { type SpaceContext } from "../../context/space.context.js";
import { MediaEntity } from "../../entities/Media.entity.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/@liexp/backend/src/flows/tg/parseVideo.flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import type TelegramBot from "node-telegram-bot-api";
import { type ConfigContext } from "../../context/config.context.js";
import { type DatabaseContext } from "../../context/db.context.js";
import { type ENVContext } from "../../context/env.context.js";
import { type FFMPEGProviderContext } from "../../context/ffmpeg.context.js";
import { type FSClientContext } from "../../context/fs.context.js";
import { type HTTPProviderContext } from "../../context/http.context.js";
import {
type ImgProcClientContext,
type FFMPEGProviderContext,
type TGBotProviderContext,
} from "../../context/index.js";
import { type LoggerContext } from "../../context/logger.context.js";
Expand Down
1 change: 0 additions & 1 deletion packages/@liexp/backend/src/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/@liexp/backend/src/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import * as puppeteer from "puppeteer-core";
import { type ConfigContext } from "../context/config.context.js";
import { type DatabaseContext } from "../context/db.context.js";
import { type ENVContext } from "../context/env.context.js";
import { type FFMPEGProviderContext } from "../context/ffmpeg.context.js";
import { type FSClientContext } from "../context/fs.context.js";
import { type HTTPProviderContext } from "../context/http.context.js";
import {
type FFMPEGProviderContext,
type ImgProcClientContext,
type NERProviderContext,
type TGBotProviderContext,
Expand Down
2 changes: 1 addition & 1 deletion packages/@liexp/backend/src/test/mocks/mock.utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fp } from "@liexp/core/lib/fp/index.js";
import { type TaskEither } from "fp-ts/lib/TaskEither";
import { type TaskEither } from "fp-ts/lib/TaskEither.js";
import { type MockInstance } from "vitest";
import { type DeepMockProxy } from "vitest-mock-extended";

Expand Down
2 changes: 0 additions & 2 deletions services/api/src/context/context.type.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { type DatabaseContext } from "@liexp/backend/lib/context/db.context.js";
import { type FSClientContext } from "@liexp/backend/lib/context/fs.context.js";
import {
type FFMPEGProviderContext,
type GeocodeProviderContext,
type NERProviderContext,
type WikipediaProviderContext,
Expand Down Expand Up @@ -46,7 +45,6 @@ export type ServerContext = ENVContext &
NERProviderContext &
URLMetadataContext &
PuppeteerProviderContext &
FFMPEGProviderContext &
ConfigContext &
QueuesProviderContext &
BlockNoteContext &
Expand Down
4 changes: 1 addition & 3 deletions tsconfig.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
"noEmit": true,
"allowJs": true,
"module": "commonjs",
"types": [
"vitest/globals"
],
"types": ["vitest/globals"],
"declaration": false,
"skipLibCheck": true,
"skipDefaultLibCheck": true,
Expand Down

0 comments on commit 4a15253

Please sign in to comment.