Merge remote-tracking branch 'origin/develop' into feature/bildausschnitt
This commit is contained in:
commit
05dc1170aa
8 files changed
+293
-60
No files matched your search
@@ -53,6 +53,7 @@ public function writeUnlessRecent(
|
||||
string $action,
|
||||
string $format,
|
||||
string $marking,
|
||||
string|\Closure|null $checksum = null,
|
||||
): bool {
|
||||
$recent = MediaDelivery::query()
|
||||
->where('grant_id', $grant->id)
|
||||
@@ -65,7 +66,7 @@ public function writeUnlessRecent(
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->write($grant, $article, $release, $version, $action, $format, null, $marking);
|
||||
$this->write($grant, $article, $release, $version, $action, $format, $checksum instanceof \Closure ? $checksum() : $checksum, $marking);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Media;
|
||||
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
/**
|
||||
* SHA-256 einer Datei der Medienablage für den Auslieferungsnachweis (08 §7), je Datei einmal berechnet.
|
||||
*
|
||||
* Die Dateien sind nach dem Speichern unveränderlich. Der gemerkte Wert gilt daher für Pfad, Größe und Änderungszeit;
|
||||
* ändert sich eine davon, wird neu gerechnet. Ist die Datei nicht lesbar, ist das Ergebnis null (der Nachweis nennt
|
||||
* dann keine Prüfsumme, statt die Auslieferung zu blockieren).
|
||||
*/
|
||||
class FileChecksum
|
||||
{
|
||||
public function of(string $diskName, string $path): ?string
|
||||
{
|
||||
$disk = Storage::disk($diskName);
|
||||
|
||||
try {
|
||||
if (! $disk->exists($path)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$key = 'media-checksum:'.hash('sha256', $diskName.'|'.$path.'|'.$disk->size($path).'|'.$disk->lastModified($path));
|
||||
|
||||
return Cache::rememberForever($key, function () use ($disk, $path): ?string {
|
||||
$stream = $disk->readStream($path);
|
||||
|
||||
if (! is_resource($stream)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$context = hash_init('sha256');
|
||||
hash_update_stream($context, $stream);
|
||||
|
||||
return hash_final($context);
|
||||
} finally {
|
||||
fclose($stream);
|
||||
}
|
||||
});
|
||||
} catch (\Throwable) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user