From 85244861c732d9ed87ba206d92f770dd9b0b8b73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20P=C3=B6mp?= Date: Mon, 18 Sep 2023 18:53:53 +0200 Subject: [PATCH] refactor(octra): json-sets library is blocking --- email-sender/index.php | 397 ------------------ libs/annotation/src/lib/annotation.ts | 3 +- libs/json-sets/README.md | 75 +--- libs/json-sets/package.json | 5 +- libs/json-sets/project.json | 8 +- libs/json-sets/{ => src}/LICENSE.txt | 0 libs/json-sets/src/README.md | 74 ++++ libs/json-sets/src/lib/interfaces.ts | 4 +- libs/json-sets/src/lib/json-set-validator.ts | 13 +- libs/json-sets/tsconfig.json | 4 +- libs/web-media/src/lib/data-info/file-info.ts | 22 +- 11 files changed, 117 insertions(+), 488 deletions(-) delete mode 100644 email-sender/index.php rename libs/json-sets/{ => src}/LICENSE.txt (100%) create mode 100644 libs/json-sets/src/README.md diff --git a/email-sender/index.php b/email-sender/index.php deleted file mode 100644 index 33fa6fb57..000000000 --- a/email-sender/index.php +++ /dev/null @@ -1,397 +0,0 @@ - - - - <?php echo $topic; ?> - - - - -
-

- Installation: "> - - - - - - - - - - - - - - - - - -
Message:", $data["description"]); ?>
Email Address:
OS:
Platform:
- - 0): ?> -

Screenshots:

-
- - " alt="scrrenshot"/> -
- -
- - -

Report:

- - - - - $value): ?> - - - - - - -
- - - - - - - - - - - - - - - - - - - -
Errors:Warnings:Information:Total items:
- - - - - - - - - - - - 0) { - $last_number = count($data["report"]["entries"]); - $max_decimals = strlen((string)$last_number); - } - foreach ($data["report"]["entries"] as $entry): - $number++; - $lineNumber = sprintf('%0' . $max_decimals . 'd', $number); - ?> - - - - - - - - - -
#DateTypeDescription
- - 0 - - - 1 - - - 2 - - - 3 - - - >", $entry["message"]); ?>
- -

No protocol available.

- -
- - - $value) { - if (substr($name, 0, 5) == 'HTTP_') { - $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; - } - } - return $headers; - } -} -$headers = getallheaders(); - -$result = array( - "status" => "failed", - "error" => "" -); - -if (!empty($data) && !is_null($headers["Authorization"]) && $headers["Authorization"] === $auth_token) { - $data = json_decode($data, true); - - if (!is_null($data["additional_information"]) && !is_null($data["description"])) { - - $attachments = array(); - foreach ($_FILES AS $file) { - $size = $file["size"]; - $file_data = file_get_contents($file["tmp_name"]); - $file_data = base64_encode($file_data); - $type = $file["type"]; - - $attachments[] = array("name" => $file["name"], "size" => $size, "type" => $type, "data" => $file_data); - } - - $from_email = $data["additional_information"]["email"]; - - if (!empty($data["additional_information"]["name"])) { - $from_name = $data["additional_information"]["name"]; - } else { - $from_name = ""; - } - - $timestamp = date("Y-m-d-H-i-s"); - $topic = "OCTRA Feedback [$timestamp]"; - - - if (empty($from_email)) { - $from_email = "do-not-reply@octra.net"; - } - - $separator = md5(uniqid(microtime(), true)); - $eol = "\r\n"; - - if ($from_name != "") { - $header = "From: \"$from_name\" <" . $from_email . ">" . $eol; - } else { - $header = "From: " . $from_email . $eol; - } - $header .= "Reply-To: " . $from_email . $eol; - - $header .= "MIME-Version: 1.0" . $eol; - $header .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\"" . $eol; - $header .= "Content-Transfer-Encoding: 8bit" . $eol; - $header .= "This is a MIME encoded message." . $eol; - - // message - $body = "--" . $separator . $eol; - $body .= "Content-Type: text/html; charset=\"UTF-8\"" . $eol; - $body .= "Content-Transfer-Encoding: 8bit" . $eol . $eol; - $body .= getHTMLText($data, $attachments) . $eol; - - //attachments - /* - foreach($attachments as $file){ - print_r($file); - $data = chunk_split(base64_encode($file['data'])); - $body .= "--" . $separator . $eol; - $body .= "Content-Location: CID:somethingatelse ;\r\n"; - $body .= "Content-ID: ;\r\n"; - $body.= "Content-Disposition: attachment;\r\n"; - $body.= "\tfilename=\"".$file['name']."\";\r\n"; - $body.= "Content-Length: .".$file['size'].";\r\n"; - $body.= "Content-Type: ".$file['type'].";\r\n"; - $body.= "Content-Transfer-Encoding: base64\r\n\r\n"; - $body.= $data."\r\n"; - }*/ - $body .= "--" . $separator . "--"; - - // echo "send email to $to_email from $from_email, with topic $topic"; - $send_ok = mail($to_email, $topic, $body, $header); - - if (!$send_ok) { - $result["status"] = 'failed'; - $result["error"] = 'could not send mail'; - } else { - $result["status"] = "success"; - } - - } else { - $result["status"] = "failed"; - $result["error"] = "Object posted does not have valid attributes"; - } -} else { - $result = array( - "status" => "failed", - "error" => "No Post request or invalid auth token" - ); -} - -echo json_encode($result); - -?> diff --git a/libs/annotation/src/lib/annotation.ts b/libs/annotation/src/lib/annotation.ts index 36d9782ba..baa363c35 100644 --- a/libs/annotation/src/lib/annotation.ts +++ b/libs/annotation/src/lib/annotation.ts @@ -18,7 +18,6 @@ import { OctraAnnotationEvent, OctraAnnotationSegment, } from './octraAnnotationSegment'; -import { last } from '@octra/utilities'; export class OctraAnnotationLink { get id(): number { @@ -693,7 +692,7 @@ export class OctraAnnotationSegmentLevel< name: this.level.name, type: this.type, }; - const lastItem = last(res.items)!; + const lastItem = res.items[res.items.length - 1]; if (lastItem.sampleStart + lastItem.sampleDur < lastSegmentTime.samples) { res.items.push( new OSegment( diff --git a/libs/json-sets/README.md b/libs/json-sets/README.md index 4a470b7c7..e167d5b09 100644 --- a/libs/json-sets/README.md +++ b/libs/json-sets/README.md @@ -1,74 +1 @@ -# json-sets - -This library allows to define sets using JSON. JSONSetValidator parsed an array of objects and validates it using the JSON definition. - -## Installation - -### ESM, CJS & TS definitions - -Currently, the libraries are not published on npm because Octra 2.0 and the libraries are still in development. If you -want to use the libraries in your project you have to manually install. - -1. Clone the OCTRA repository next to the project folder you want to use the libraries for. -2. Switch tu branch "static". - -```shell -git checkout static -``` - -3. Now go to your project folder and run - -```shell -npm install --legacy-peer-deps "../octra/libs/json-sets" -``` - -### UMD Bundle (Vanilla JS) - -Do steps 1 and 2 from the previous chapter and reference it in an HTML -file ([see full example here](../../apps/web-components-demo/index.html)). - -````html - - - - - - -```` - -## Update - -1. Go to the cloned octra repository. Make sure you are in branch `static`. -2. Update directory: - -```shell -git pull -``` - -## Use - -### Import - -#### ESM, Typescript - -Import the classes and functions from `@octra/json-sets`. For example - -````typescript -import {JsonSetValidator} from "@octra/json-sets"; -```` - -#### UMD Bundle - -All functions and classes are available via global scope `OctraJSONSets`. For example: - -```javascript -/* -make sure that you have injected the umd bundle as described before. - */ -const validator = new OctraJSONSets.JSONSetValidator(); -``` - -### API - -You can find more information about classes and functions of `@octra/json-sets` [here](https://ips-lmu.github.io/octra/modules/_octra_json_sets.html). - +[GO TO README HERE](./src/README.md) diff --git a/libs/json-sets/package.json b/libs/json-sets/package.json index c17766c4a..de58f4d44 100644 --- a/libs/json-sets/package.json +++ b/libs/json-sets/package.json @@ -1,5 +1,6 @@ { "name": "@octra/json-sets", - "version": "0.0.1", - "type": "commonjs" + "version": "0.0.5", + "type": "module", + "private": false } diff --git a/libs/json-sets/project.json b/libs/json-sets/project.json index 7690cade6..c7ed72b72 100644 --- a/libs/json-sets/project.json +++ b/libs/json-sets/project.json @@ -13,12 +13,12 @@ "tsConfig": "libs/json-sets/tsconfig.lib.json", "entryFile": "libs/json-sets/src/index.ts", "project": "libs/json-sets/package.json", - "compiler": "babel", + "compiler": "tsc", "external": ["typescript"], - "format": ["cjs", "esm"], + "format": ["cjs"], "assets": [ - "libs/json-sets/LICENSE.txt", - "libs/json-sets/README.md" + "libs/json-sets/src/LICENSE.txt", + "libs/json-sets/src/README.md" ] } }, diff --git a/libs/json-sets/LICENSE.txt b/libs/json-sets/src/LICENSE.txt similarity index 100% rename from libs/json-sets/LICENSE.txt rename to libs/json-sets/src/LICENSE.txt diff --git a/libs/json-sets/src/README.md b/libs/json-sets/src/README.md new file mode 100644 index 000000000..554a1f96b --- /dev/null +++ b/libs/json-sets/src/README.md @@ -0,0 +1,74 @@ +# json-sets (still in development) + +This library allows to define sets using JSON. JSONSetValidator parsed an array of objects and validates it using the JSON definition. + +## Installation + +### ESM, CJS & TS definitions + +Currently, the libraries are not published on npm because Octra 2.0 and the libraries are still in development. If you +want to use the libraries in your project you have to manually install. + +1. Clone the OCTRA repository next to the project folder you want to use the libraries for. +2. Switch tu branch "static". + +```shell +git checkout static +``` + +3. Now go to your project folder and run + +```shell +npm install --legacy-peer-deps "../octra/libs/json-sets" +``` + +### UMD Bundle (Vanilla JS) + +Do steps 1 and 2 from the previous chapter and reference it in an HTML +file ([see full example here](../../apps/web-components-demo/index.html)). + +````html + + + + + + +```` + +## Update + +1. Go to the cloned octra repository. Make sure you are in branch `static`. +2. Update directory: + +```shell +git pull +``` + +## Use + +### Import + +#### ESM, Typescript + +Import the classes and functions from `@octra/json-sets`. For example + +````typescript +import {JsonSetValidator} from "@octra/json-sets"; +```` + +#### UMD Bundle + +All functions and classes are available via global scope `OctraJSONSets`. For example: + +```javascript +/* +make sure that you have injected the umd bundle as described before. + */ +const validator = new OctraJSONSets.JSONSetValidator(); +``` + +### API + +You can find more information about classes and functions of `@octra/json-sets` [here](https://ips-lmu.github.io/octra/modules/_octra_json_sets.html). + diff --git a/libs/json-sets/src/lib/interfaces.ts b/libs/json-sets/src/lib/interfaces.ts index 9cc9612d7..20fca3140 100644 --- a/libs/json-sets/src/lib/interfaces.ts +++ b/libs/json-sets/src/lib/interfaces.ts @@ -1,6 +1,4 @@ -export interface FileMetaData {} - -export interface AudioFileMetaData extends FileMetaData { +export interface AudioFileMetaData { bitRate?: number; numberOfChannels?: number; duration?: { samples: number; seconds: number }; diff --git a/libs/json-sets/src/lib/json-set-validator.ts b/libs/json-sets/src/lib/json-set-validator.ts index 561eedc18..daddba766 100644 --- a/libs/json-sets/src/lib/json-set-validator.ts +++ b/libs/json-sets/src/lib/json-set-validator.ts @@ -31,11 +31,18 @@ export class JSONSetValidator { } } +export interface IFile { + name: string; + size: number; + type: string; +} + export class FileJSONSetValidator extends JSONSetValidator { override validate( - set: File[], + set: IFile[], setSchema: JSONFileSetDefinition ): JSONFileSetValidationError[] { + const results: { statement: JSONSetStatement; validationResults: { @@ -59,7 +66,7 @@ export class FileJSONSetValidator extends JSONSetValidator { } override __validate( - target: File, + target: IFile, constraints: JSONSETFileConstraints, path: string ): JSONFileSetValidationError[] { @@ -165,7 +172,7 @@ export class FileJSONSetValidator extends JSONSetValidator { } private getValidFileNamesOfSelection( - pool: File[], + pool: IFile[], statement: JSONFileSetStatement, path: string ) { diff --git a/libs/json-sets/tsconfig.json b/libs/json-sets/tsconfig.json index f5b85657a..e3275c36f 100644 --- a/libs/json-sets/tsconfig.json +++ b/libs/json-sets/tsconfig.json @@ -7,7 +7,9 @@ "noImplicitOverride": true, "noPropertyAccessFromIndexSignature": true, "noImplicitReturns": true, - "noFallthroughCasesInSwitch": true + "noFallthroughCasesInSwitch": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true }, "files": [], "include": [], diff --git a/libs/web-media/src/lib/data-info/file-info.ts b/libs/web-media/src/lib/data-info/file-info.ts index 44061fdce..bf2cac616 100644 --- a/libs/web-media/src/lib/data-info/file-info.ts +++ b/libs/web-media/src/lib/data-info/file-info.ts @@ -110,8 +110,26 @@ export class FileInfo extends DataInfo { } private static getMimeTypeByExtension(extension: string) { - if (['mp4'].includes(extension)) { - return 'video/mp4'; + switch (extension.replace(/\./g, '')) { + // audio + case 'wav': + return 'audio/wave'; + case 'mp3': + return 'audio/mpeg'; + case 'ogg': + return 'audio/ogg'; + case 'opus': + return 'audio/opus'; + // video + case 'mp4': + return 'video/mp4'; + case 'png': + return 'image/png'; + case 'jpg': + return 'image/jpg'; + //document + case 'pdf': + return 'application/pdf'; } return 'text/plain'; }