Skip to content

Commit

Permalink
Merge branch 'master' into vue3
Browse files Browse the repository at this point in the history
  • Loading branch information
mzur committed Feb 13, 2025
2 parents 2a71366 + 02a3834 commit af60a08
Show file tree
Hide file tree
Showing 20 changed files with 260 additions and 58 deletions.
13 changes: 13 additions & 0 deletions app/Http/Controllers/Api/Volumes/Filters/FilenameController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ public function index($id, $pattern)
// Escape trailing backslashes, else there would be an error with ilike.
$pattern = preg_replace('/\\\\$/', '\\\\\\\\', $pattern);

$files = explode(',', $pattern);
if (count($files) > 1) {
$files = collect($files)->map(
function ($f) {
$filename = trim($f);
return strlen($filename) > 0 ? $filename : null;
}
)->whereNotNull();

return $files->chunk(1000)->flatMap(fn ($chunk)
=> $volume->files()->whereIn('filename', $chunk)->pluck('id'));
}

return $volume->files()
->where('filename', 'ilike', str_replace('*', '%', $pattern))
->pluck('id');
Expand Down
39 changes: 18 additions & 21 deletions app/Jobs/ProcessNewVideo.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,6 @@ public function handleFile($file, $path)
return;
}

if ($this->hasInvalidMoovAtomPosition($path)) {
$this->video->error = Video::ERROR_INVALID_MOOV_POS;
$this->video->save();
return;
}

$this->video->size = File::size($path);
$this->video->duration = $this->getVideoDuration($path);

Expand All @@ -149,9 +143,12 @@ public function handleFile($file, $path)
// ignore and leave dimensions at null.
}

if ($this->video->error) {
if ($this->hasInvalidMoovAtomPosition($path)) {
$this->video->error = Video::ERROR_INVALID_MOOV_POS;
} elseif ($this->video->error) {
$this->video->error = null;
}

$this->video->save();

$disk = Storage::disk(config('videos.thumbnail_storage_disk'));
Expand Down Expand Up @@ -233,20 +230,6 @@ protected function getVideoDimensions($url)
return $this->ffprobe->streams($url)->videos()->first()->getDimensions();
}

protected function hasInvalidMoovAtomPosition($sourcePath)
{
// Webm and mpeg videos don't have a moov atom
if (in_array($this->video->mimeType, ['video/mpeg', 'video/webm'])) {
return false;
}

$process = Process::forever()
->run("ffprobe -v trace -i '{$sourcePath}' 2>&1 | grep -o -e type:\'mdat\' -e type:\'moov\'")
->throw();
$output = explode("\n", $process->output());
return !str_contains($output[0], 'moov');
}

/**
* Extract images from video.
*
Expand Down Expand Up @@ -346,4 +329,18 @@ protected function generateThumbnail(string $file, int $width, int $height): Vip
{
return VipsImage::thumbnail($file, $width, ['height' => $height]);
}

protected function hasInvalidMoovAtomPosition($sourcePath)
{
// Webm and mpeg videos don't have a moov atom
if (in_array($this->video->mimeType, ['video/mpeg', 'video/webm'])) {
return false;
}

$process = Process::forever()
->run("ffprobe -v trace -i '{$sourcePath}' 2>&1 | grep -o -e type:\'mdat\' -e type:\'moov\'")
->throw();
$output = explode("\n", $process->output());
return !str_contains($output[0], 'moov');
}
}
11 changes: 10 additions & 1 deletion app/Rules/VolumeUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,16 @@ protected function passesDiskUrl($value)
return false;
}

if (empty($disk->files($url[1])) && empty($disk->directories($url[1]))) {
// Access the adapter directly to check for contents without loading the full
// file/directory listing.
$iterable = $disk->getAdapter()->listContents($url[1], false);
$hasContent = false;
foreach ($iterable as $item) {
$hasContent = true;
break;
}

if (!$hasContent) {
$this->message = "Unable to access '{$url[1]}'. Does it exist and you have access permissions?";

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ protected function query()
* @param string $title The title to put in the first row of the CSV
* @return CsvFile
*/
protected function createCsv($labels, $title = "\n")
protected function createCsv($labels, $title = '')
{
$csv = CsvFile::makeTmp();
// The title must not be empty as the Python
Expand Down
2 changes: 1 addition & 1 deletion config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

'migrations' => [
'table' => 'migrations',
'update_date_on_publish' => true,
'update_date_on_publish' => false,
],

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@ import Styles from '@/annotations/stores/styles.js';
import { shiftKeyOnly } from '@biigle/ol/events/condition';
import snapInteraction from '@/annotations/ol/snapInteraction.js';
import { Point } from '@biigle/ol/geom';
import * as preventDoubleclick from '../../../prevent-doubleclick';
function computeDistance(point1, point2) {
let p1=point1.getCoordinates();
let p2=point2.getCoordinates();
return Math.sqrt(Math.pow(p2[0] - p1[0], 2) + Math.pow(p2[1] - p1[1], 2));
}
/**
* Mixin for the annotationCanvas component that contains logic for the draw interactions.
*
Expand All @@ -21,9 +16,6 @@ function computeDistance(point1, point2) {
let drawInteraction;
const POINT_CLICK_COOLDOWN = 400;
const POINT_CLICK_DISTANCE = 5;
// Custom OpenLayers freehandCondition that is true if a pen is used for input or
// if Shift is pressed otherwise.
let penOrShift = function (mapBrowserEvent) {
Expand Down Expand Up @@ -142,8 +134,8 @@ export default {
}
},
isPointDoubleClick(e) {
return new Date().getTime() - this.lastDrawnPointTime < POINT_CLICK_COOLDOWN
&& computeDistance(this.lastDrawnPoint,e.feature.getGeometry()) < POINT_CLICK_DISTANCE;
return new Date().getTime() - this.lastDrawnPointTime < preventDoubleclick.POINT_CLICK_COOLDOWN
&& preventDoubleclick.computeDistance(this.lastDrawnPoint,e.feature.getGeometry()) < preventDoubleclick.POINT_CLICK_DISTANCE;
},
},
watch: {
Expand Down
18 changes: 18 additions & 0 deletions resources/assets/js/prevent-doubleclick.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Compute the Euclidean distance between two points.
*
* @param Object point1 - The first point with getCoordinates() method.
* @param Object point2 - The second point with getCoordinates() method.
* @returns number - The computed distance between the two points.
*/

const POINT_CLICK_COOLDOWN = 400;
const POINT_CLICK_DISTANCE = 5;

let computeDistance = function (point1, point2) {
let p1 = point1.getCoordinates();
let p2 = point2.getCoordinates();
return Math.sqrt(Math.pow(p2[0] - p1[0], 2) + Math.pow(p2[1] - p1[1], 2));
};

export { computeDistance, POINT_CLICK_COOLDOWN, POINT_CLICK_DISTANCE };
3 changes: 1 addition & 2 deletions resources/assets/js/projects/components/charts/IDToColor.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@ export function IDToColor(id) {
const hue = id % 360;
const saturation = 70 + (id % 31); // Ensure saturation is between 70 and 100
const lightness = 70 + (id % 21); // Ensure lightness is between 70 and 90

return `hsl(${hue} ${saturation}% ${lightness}%)`;
return `hsl(${hue}, ${saturation}%, ${lightness}%)`;
}
12 changes: 12 additions & 0 deletions resources/assets/js/videos/components/settingsTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default {
'enableJumpByFrame',
'jumpStep',
'muteVideo',
'singleAnnotation',
],
annotationOpacity: 1,
showMinimap: true,
Expand All @@ -62,6 +63,7 @@ export default {
showThumbnailPreview: true,
enableJumpByFrame: false,
muteVideo: true,
singleAnnotation: false,
};
},
computed: {
Expand Down Expand Up @@ -112,6 +114,12 @@ export default {
handleUnmuteVideo() {
this.muteVideo = false;
},
handleSingleAnnotation() {
this.singleAnnotation = true;
},
handleDisableSingleAnnotation() {
this.singleAnnotation = false;
},
toggleAnnotationOpacity() {
if (this.annotationOpacity > 0) {
this.annotationOpacity = 0;
Expand Down Expand Up @@ -172,6 +180,10 @@ export default {
this.$emit('update', 'muteVideo', show);
Settings.set('muteVideo', show);
},
singleAnnotation(show) {
this.$emit('update', 'singleAnnotation', show);
Settings.set('singleAnnotation', show);
},
},
created() {
this.restoreKeys.forEach((key) => {
Expand Down
Loading

0 comments on commit af60a08

Please sign in to comment.