Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
4rthem committed Oct 11, 2023
1 parent f0fd954 commit 065f1a1
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 28 deletions.
6 changes: 6 additions & 0 deletions bin/dev/debug-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

. bin/functions.sh
load-env

env
11 changes: 6 additions & 5 deletions bin/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ function load-env {
exit 1
fi

tmp="/tmp/env-$(tr -dc A-Za-z0-9 </dev/urandom | head -c 13 ; echo '')"
tmp="/tmp/env-$(cat /dev/urandom | LC_ALL=C tr -dc 'A-Za-z0-9' | head -c 13 ; echo '')"
env > "${tmp}"

export_env_from_file ".env.local"
export_env_from_file ".env"
export_env_from_file ".env.local"

eval "$(
while read -r LINE; do
if [[ $LINE =~ ^[A-Za-z0-9]+= ]] && [[ $LINE != '#'* ]]; then
if [[ $LINE =~ ^[A-Za-z0-9_]+= ]] && [[ $LINE != '#'* ]]; then
key=$(printf '%s\n' "$LINE"| sed 's/"/\\"/g' | cut -d '=' -f 1)
value=$(printf '%s\n' "$LINE" | cut -d '=' -f 2- | sed 's/"/\\\"/g')
printf '%s\n' "export $key=\"$value\""
Expand All @@ -40,13 +41,13 @@ function load-env {

# execute a shell commmand in a container defined in docker-compose.yml
function exec_container() {
docker compose exec -T "$1" sh -c "$2"
docker compose exec -T "$1" sh -c "$2"
}

function exec_container_as() {
docker compose exec -T "$1" su "$3" sh -c "$2"
docker compose exec -T "$1" su "$3" sh -c "$2"
}

function create_db() {
exec_container db "psql -U \"${POSTGRES_USER}\" -tc \"SELECT 1 FROM pg_database WHERE datname = '$1'\" | grep -q 1 || psql -U \"${POSTGRES_USER}\" -c \"CREATE DATABASE $1\""
exec_container db "psql -U \"${POSTGRES_USER}\" -tc \"SELECT 1 FROM pg_database WHERE datname = '$1'\" | grep -q 1 || psql -U \"${POSTGRES_USER}\" -c \"CREATE DATABASE $1\""
}
8 changes: 0 additions & 8 deletions bin/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ bin/create-config.sh

set -ex

export AUTH_API_BASE_URL=https://api-auth.${PHRASEA_DOMAIN}
export UPLOADER_CLIENT_BASE_URL=https://uploader.${PHRASEA_DOMAIN}
export DATABOX_CLIENT_BASE_URL=https://databox.${PHRASEA_DOMAIN}
export UPLOADER_API_BASE_URL=https://api-uploader.${PHRASEA_DOMAIN}
export DATABOX_API_BASE_URL=https://api-databox.${PHRASEA_DOMAIN}
export NOTIFY_API_BASE_URL=https://api-notify.${PHRASEA_DOMAIN}
export EXPOSE_API_BASE_URL=https://api-expose.${PHRASEA_DOMAIN}

docker compose up -d

# Wait for services to be ready
Expand Down
8 changes: 4 additions & 4 deletions expose/api/src/Controller/Admin/AssetCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ public function configureFields(string $pageName): iterable
$position = NumberField::new('position');

if (Crud::PAGE_INDEX === $pageName) {
return [$id, $publication, $originalName, $size, $geoPoint, $path, $position, $createdAt];
return [$id, $publication, $title, $originalName, $size, $geoPoint, $path, $position, $createdAt];
} elseif (Crud::PAGE_DETAIL === $pageName) {
return [$id, $assetId, $path, $size, $publication, $title, $description, $originalName, $mimeType, $ownerId, $lat, $lng, $webVTT, $altitude, $createdAt, $clientAnnotations, $subDefinitions];
return [$id, $assetId, $title, $path, $size, $publication, $description, $originalName, $mimeType, $ownerId, $lat, $lng, $webVTT, $altitude, $createdAt, $clientAnnotations, $subDefinitions];
} elseif (Crud::PAGE_NEW === $pageName) {
return [$publication, $originalName, $description, $lat, $lng, $altitude, $webVTT, $clientAnnotations];
return [$publication, $title, $originalName, $description, $lat, $lng, $altitude, $webVTT, $clientAnnotations];
} elseif (Crud::PAGE_EDIT === $pageName) {
return [$publication, $originalName, $description, $lat, $lng, $altitude, $webVTT, $clientAnnotations];
return [$publication, $title, $originalName, $description, $lat, $lng, $altitude, $webVTT, $clientAnnotations];
}

return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class GalleryLayout extends React.Component {
};

render() {
const {assetId, data, options} = this.props;
const {data, options} = this.props;
const {currentIndex} = this.state;
const {
assets,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,34 @@ export default function AssetProxy({
}
}, [isCurrent]);

const type = asset.mimeType;
const mediaType = getMediaType(type);

React.useEffect(() => {
if (isCurrent && containerRef.current) {
pushInstruction('MediaAnalytics::enableMediaAnalytics');
pushInstruction('MediaAnalytics::setPingInterval', 1);
pushInstruction('MediaAnalytics::scanForMedia');
if (process.env.NODE_ENV !== 'production') {
pushInstruction('MediaAnalytics::enableDebugMode');
}

if (asset.assetId) {
pushInstruction('trackContentImpression', asset.title ?? asset.id, asset.assetId);
}

if ([MediaType.Audio, MediaType.Video].includes(mediaType)) {
pushInstruction('MediaAnalytics::setPingInterval', 10);
pushInstruction('MediaAnalytics::scanForMedia', containerRef.current);
}
}
}, [containerRef, isCurrent]);
}, [containerRef, isCurrent, mediaType]);

let content: JSX.Element;
const type = asset.mimeType;

switch (true) {
case 'application/pdf' === type:
switch (mediaType) {
case MediaType.Document:
content = <PDFViewer file={asset.previewUrl}/>
break;
case type.startsWith('video/'):
case type.startsWith('audio/'):
case MediaType.Video:
case MediaType.Audio:
content = <VideoPlayer
ref={videoRef}
url={asset.previewUrl}
Expand All @@ -56,7 +67,7 @@ export default function AssetProxy({
assetId={asset.assetId}
/>
break;
case type.startsWith('image/'):
case MediaType.Image:
if (magnifier) {
content = <Magnifier
imageSrc={asset.previewUrl}
Expand All @@ -71,6 +82,7 @@ export default function AssetProxy({
/>
}
break;
case MediaType.Unknown:
default:
content = <div>Unsupported media type</div>
break;
Expand All @@ -83,3 +95,25 @@ export default function AssetProxy({
{content}
</div>
}

enum MediaType {
Image,
Video,
Audio,
Document,
Unknown,
}

function getMediaType(type: string): MediaType {
switch (true) {
case 'application/pdf' === type:
return MediaType.Document;
case type.startsWith('video/'):
return MediaType.Video;
case type.startsWith('audio/'):
case type.startsWith('image/'):
return MediaType.Image;
default:
return MediaType.Unknown;
}
}
3 changes: 3 additions & 0 deletions expose/client/src/lib/matomo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ export const matomo = matomoConfig ? createInstance({
urlBase: matomoConfig.baseUrl,
siteId: parseInt(matomoConfig.siteId),
linkTracking: false,
configurations: {
setSecureCookie: true,
}
}) : undefined;
1 change: 1 addition & 0 deletions expose/client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type Asset = {
id: string;
publication: Publication;
mimeType: string;
assetId: string | undefined;
previewUrl: string;
posterUrl: string;
title: string;
Expand Down

0 comments on commit 065f1a1

Please sign in to comment.