Skip to content

Commit

Permalink
Bumping version number, removing duplicate versioning and fixing linting
Browse files Browse the repository at this point in the history
  • Loading branch information
bcd00 committed Aug 14, 2024
1 parent 14f20be commit e1d40b0
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 26 deletions.
3 changes: 1 addition & 2 deletions apps/ove-client/src/open-api.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { app } from "electron";
import { env } from "./env";
import { appRouter } from "./server/router";
import { generateOpenApiDocument } from "trpc-openapi";

export const openApiDocument = generateOpenApiDocument(appRouter, {
title: env.TITLE,
description: env.DESCRIPTION,
version: app.getVersion(),
version: env.API_VERSION.toString(),
baseUrl: `${env.PROTOCOL}://${env.HOSTNAME}:${env.PORT}/api/v${env.API_VERSION}`
});
22 changes: 13 additions & 9 deletions apps/ove-core-ui/src/pages/project-editor/file-upload/upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { actionColors } from "../utils";
import { trpc } from "../../../utils/api";
import type { FileUploadForm } from "./file-upload";
import type { UseFormRegister } from "react-hook-form";
import React, { FormEventHandler, useRef } from "react";
import React, { FormEventHandler, useCallback, useRef } from "react";
import { type File as FileT, dataTypes } from "@ove/ove-types";
import { Brush, Gear, Upload as UploadButton, X } from "react-bootstrap-icons";

Expand Down Expand Up @@ -39,6 +39,15 @@ const Upload = ({
const fileRef = useRef<HTMLInputElement | null>(null);
const formRef = useRef<HTMLFormElement | null>(null);
const processImage = trpc.projects.formatDZI.useMutation({ retry: false });
const process = useCallback(
(bucketName: string, fileName: string) => processImage.mutateAsync({
bucketName,
objectName: fileName,
versionId: getLatest(bucketName, fileName).version
})
.then(() => toast.info(`Converted ${fileName} to DZI`))
.catch(() => toast.error(`Error converting ${fileName} to DZI`)),
[processImage, getLatest]);

return <section
id={styles["upload"]}>
Expand All @@ -49,18 +58,13 @@ const Upload = ({
<ul>
{names.map((name, i) => {
const [bucketName, fileName] = name.split("/");
const isImage = name.match(/.*(?:png|jpg|jpeg|PNG|JPG|JPEG)$/g) !== null;
const isImage = name
.match(/.*(?:png|jpg|jpeg|PNG|JPG|JPEG)$/g) !== null;
return <li key={name}
style={{ backgroundColor: colors[i % names.length] }}>
{name}
{isImage ? <button className={styles.ml} title="process image"
onClick={() => processImage.mutateAsync({
bucketName,
objectName: fileName,
versionId: getLatest(bucketName, fileName).version
})
.then(() => toast.info(`Converted ${fileName} to DZI`))
.catch(() => toast.error(`Error converting ${fileName} to DZI`))}>
onClick={() => process(bucketName, fileName)}>
<Gear /></button> : null}
{/* @ts-expect-error - readOnly prop is not known on type */}
<select readOnly={true} className={isImage ? undefined : styles.ml}
Expand Down
1 change: 0 additions & 1 deletion apps/ove-core/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ const schema = baseSchema.refine(config =>

const staticConfig = {
APP_NAME: "ove-core",
VERSION: "0.2.0",
API_VERSION: 1,
TITLE: "next-ove core",
DESCRIPTION: "The heart of next-ove."
Expand Down
2 changes: 1 addition & 1 deletion apps/ove-core/src/server/open-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import { generateOpenApiDocument } from "trpc-openapi";
export const openApiDocument = generateOpenApiDocument(appRouter, {
title: env.TITLE,
description: env.DESCRIPTION,
version: env.VERSION,
version: env.API_VERSION.toString(),
baseUrl: `${env.PROTOCOL}://${env.HOSTNAME}:${env.PORT}/api/v${env.API_VERSION}`,
});
40 changes: 28 additions & 12 deletions apps/ove-core/src/server/projects/controller.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/* global __dirname */
/* global __dirname, URL, Buffer */

import http from "http";
import path from "path";
import { File } from "buffer";
import fetch from "node-fetch";
import { env } from "../../env";
import { nanoid } from "nanoid";
import unzip, { Entry } from "unzip-stream";
import type { Client } from "minio";
import service from "../auth/service";
import { readFileSync } from "atomically";
import unzip, { Entry } from "unzip-stream";
import { S3Controller } from "./s3-controller";
import { type DataTypes, isError } from "@ove/ove-types";
import type { Controller, DataFormatConfigOptions } from "./router";
Expand Down Expand Up @@ -219,11 +219,13 @@ const groupBy = <T extends object>(xs: T[], key: keyof T) =>
return rv;
}, {} as { [_Key in keyof T]: T[] });

const addLatest = <T extends {
versionId: string,
isLatest: boolean,
type RawFile = {
versionId: string
isLatest: boolean
lastModified: Date
}>(files: T[]): T[] =>
}

const addLatest = <T extends RawFile>(files: T[]): T[] =>
files.concat(files.filter(({ isLatest }) => isLatest).map(file => ({
...file,
versionId: "latest",
Expand All @@ -234,7 +236,10 @@ const addLatest = <T extends {
const getProjectFiles = async (s3: Client, bucketName: string) => {
const files = (await S3Controller.listObjects(s3, bucketName))
.filter(obj => !obj.name.includes("/") || obj.name.endsWith("dzi"))
.map(obj => ({...obj, name: obj.name.includes("/") ? obj.name.split("/")[0] : obj.name}));
.map(obj => ({
...obj,
name: obj.name.includes("/") ? obj.name.split("/")[0] : obj.name
}));
return Object.values(groupBy(files, "name"))
.map(group => group.sort((a, b) =>
a.lastModified.getTime() - b.lastModified.getTime())
Expand All @@ -249,7 +254,10 @@ const getGlobalFiles = async (s3: Client): ReturnType<Controller["getFiles"]> =>
.map(async bucket => {
const objects = (await S3Controller.listObjects(s3, bucket))
.filter(obj => !obj.name.includes("/") || obj.name.endsWith("dzi"))
.map(obj => ({...obj, name: obj.name.includes("/") ? obj.name.split("/")[0] : obj.name}));
.map(obj => ({
...obj,
name: obj.name.includes("/") ? obj.name.split("/")[0] : obj.name
}));
return Object.values(groupBy(objects, "name"))
.map(group => group.sort((a, b) =>
a.lastModified.getTime() - b.lastModified.getTime())
Expand Down Expand Up @@ -611,7 +619,9 @@ const formatDZI = async (
if (s3 === null) return raise("No S3 store configured");
const url = await getPresignedGetURL(s3, bucketName, objectName, versionId);
if (isError(url)) return url;
if (env.DATA_FORMATTER === undefined) return raise("No data formatter configured");
if (env.DATA_FORMATTER === undefined) {
return raise("No data formatter configured");
}
const formatter = new URL(env.DATA_FORMATTER);
await new Promise(resolve => {
const data = Json.stringify({
Expand All @@ -632,11 +642,16 @@ const formatDZI = async (
const req = http.request(options, res => {
res.pipe(unzip.Parse())
.on("entry", async (entry: Entry) => {
const dziObjectName = `${objectName.replaceAll(/(?:png|jpg|jpeg|PNG|JPEG|JPG)$/g, "dzi")}/${entry.path}`;
const entryURL = await S3Controller.getPresignedPutURL(s3, bucketName, dziObjectName);
const dziRootName =
objectName.replaceAll(/(?:png|jpg|jpeg|PNG|JPEG|JPG)$/g, "dzi");
const dziObjectName = `${dziRootName}/${entry.path}`;
const entryURL = await S3Controller
.getPresignedPutURL(s3, bucketName, dziObjectName);

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const [size, chunks] = await new Promise<[number, any[]]>(resolve => {
let size = 0;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const chunks: any[] = [];
entry.on("data", chunk => {
size += chunk.length;
Expand All @@ -647,7 +662,8 @@ const formatDZI = async (
});
await fetch(entryURL, {
method: "PUT",
body: await (new File([Buffer.from(chunks)], entry.path)).arrayBuffer(),
body: await (new File([Buffer.from(chunks)], entry.path))
.arrayBuffer(),
headers: { "Content-Length": `${size}` }
});
}).on("finish", resolve);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"email": "bc2918@ic.ac.uk"
},
"description": "The next generation of the Open Visualisation Environment.",
"version": "0.2.0",
"version": "0.2.1",
"license": "MIT",
"scripts": {
"analyze-bundle": "npm run analyze-bundle:bridge && npm run analyze-bundle:client && npm run analyze-bundle:core",
Expand Down

0 comments on commit e1d40b0

Please sign in to comment.