Browse Source

use document ID as the snap location

main
yggverse 8 months ago
parent
commit
a3f2ab0aa2
  1. 4
      src/cli/document/clean.php
  2. 16
      src/cli/document/crawl.php
  3. 12
      src/webui/api.php
  4. 36
      src/webui/explore.php

4
src/cli/document/clean.php

@ -116,9 +116,7 @@ foreach ($config->cli->document->crawl->skip->stripos->url as $condition)
implode( implode(
'/', '/',
str_split( str_split(
md5( $document->getId()
$document->get('url')
)
) )
) )
); );

16
src/cli/document/crawl.php

@ -13,14 +13,14 @@ function getLastSnapTime(array $files): int
foreach ($files as $file) foreach ($files as $file)
{ {
if (in_array($file, ['.', '..'])) if (is_dir($filename) || is_link($filename) || str_starts_with('.'))
{ {
continue; continue;
} }
$time[] = preg_replace( $time[] = preg_replace(
'/\D/', '/^([\d]+)\.tar\.gz&/',
'', '$1',
basename( basename(
$file $file
) )
@ -704,10 +704,6 @@ foreach($index->search('')
// Generate path // Generate path
$time = time(); $time = time();
$md5url = md5(
$document->get('url')
);
/// absolute /// absolute
if (str_starts_with($config->snap->storage->tmp->directory, '/')) if (str_starts_with($config->snap->storage->tmp->directory, '/'))
{ {
@ -725,7 +721,7 @@ foreach($index->search('')
$tmp = sprintf( $tmp = sprintf(
'%s/%s.%s.tar', '%s/%s.%s.tar',
$filepath, $filepath,
$md5url, $document->getId(),
$time $time
); );
@ -822,7 +818,7 @@ foreach($index->search('')
implode( implode(
'/', '/',
str_split( str_split(
$md5url $document->getId()
) )
) )
); );
@ -960,7 +956,7 @@ foreach($index->search('')
$filepath = implode( $filepath = implode(
'/', '/',
str_split( str_split(
$md5url $document->getId()
) )
); );

12
src/webui/api.php

@ -42,12 +42,12 @@ switch (!empty($_GET['action']) ? $_GET['action'] : false) {
exit; exit;
case isset($_GET['md5url']) && preg_match('/^[a-f0-9]{32}$/', $_GET['md5url']): case isset($_GET['id']) && preg_match('/^[\d]+$/', $_GET['id']):
echo json_encode( echo json_encode(
[ [
'status' => false, 'status' => false,
'message' => _('valid md5url required') 'message' => _('valid document identifier required')
] ]
); );
@ -102,7 +102,7 @@ switch (!empty($_GET['action']) ? $_GET['action'] : false) {
implode( implode(
'/', '/',
str_split( str_split(
$_GET['md5url'] $_GET['id']
) )
), ),
$_GET['time'] $_GET['time']
@ -136,7 +136,7 @@ switch (!empty($_GET['action']) ? $_GET['action'] : false) {
header( header(
sprintf( sprintf(
'Content-Disposition: filename="snap.%s.%s"', 'Content-Disposition: filename="snap.%s.%s"',
$_GET['md5url'], $_GET['id'],
basename( basename(
$filename $filename
) )
@ -175,7 +175,7 @@ switch (!empty($_GET['action']) ? $_GET['action'] : false) {
implode( implode(
'/', '/',
str_split( str_split(
$_GET['md5url'] $_GET['id']
) )
), ),
$_GET['time'] $_GET['time']
@ -222,7 +222,7 @@ switch (!empty($_GET['action']) ? $_GET['action'] : false) {
header( header(
sprintf( sprintf(
'Content-Disposition: filename="snap.%s.%s"', 'Content-Disposition: filename="snap.%s.%s"',
$_GET['md5url'], $_GET['id'],
basename( basename(
$filename $filename
) )

36
src/webui/explore.php

@ -77,14 +77,10 @@ $icon = $identicon->getImageDataUri('webp');
$snaps = []; $snaps = [];
/// Prepare location /// Prepare location
$md5url = md5(
$document->url
);
$filepath = implode( $filepath = implode(
'/', '/',
str_split( str_split(
$md5url $document->getId()
) )
); );
@ -109,18 +105,25 @@ if ($config->snap->storage->local->enabled)
{ {
foreach ((array) scandir($directory) as $filename) foreach ((array) scandir($directory) as $filename)
{ {
if (in_array($filename, ['.', '..'])) if (is_dir($filename) || is_link($filename) || str_starts_with('.'))
{ {
continue; continue;
} }
$basename = basename($filename); $basename = basename(
$time = preg_replace('/\D/', '', $basename); $filename
);
$time = preg_replace(
'/^([\d]+)\.tar\.gz&/',
'',
$basename
);
$snaps[_('Local')][] = (object) $snaps[_('Local')][] = (object)
[ [
'source' => 'local', 'source' => 'local',
'md5url' => $md5url, 'id' => $document->getId(),
'name' => $basename, 'name' => $basename,
'time' => $time, 'time' => $time,
'size' => filesize( 'size' => filesize(
@ -161,13 +164,20 @@ foreach ($config->snap->storage->remote->ftp as $i => $ftp)
foreach ((array) $remote->nlist($filepath) as $filename) foreach ((array) $remote->nlist($filepath) as $filename)
{ {
$basename = basename($filename); $basename = basename(
$time = preg_replace('/\D/', '', $basename); $filename
);
$time = preg_replace(
'/^([\d]+)\.tar\.gz&/',
'',
$basename
);
$snaps[sprintf(_('Server #%s'), $i + 1)][] = (object) $snaps[sprintf(_('Server #%s'), $i + 1)][] = (object)
[ [
'source' => $i, 'source' => $i,
'md5url' => $md5url, 'id' => $document->getId(),
'name' => $basename, 'name' => $basename,
'time' => $time, 'time' => $time,
'size' => $remote->size($filename), 'size' => $remote->size($filename),
@ -481,7 +491,7 @@ if ($config->webui->index->enabled)
<ul> <ul>
<?php foreach ($snap as $file) { ?> <?php foreach ($snap as $file) { ?>
<li> <li>
<a rel="nofollow" href="api.php?action=snap&method=download&source=<?php echo $file->source ?>&md5url=<?php echo $file->md5url ?>&time=<?php echo $file->time ?>"> <a rel="nofollow" href="api.php?action=snap&method=download&source=<?php echo $file->source ?>&id=<?php echo $file->id ?>&time=<?php echo $file->time ?>">
<?php echo sprintf('%s (tar.gz / %s bytes)', date('c', $file->time), number_format($file->size)) ?> <?php echo sprintf('%s (tar.gz / %s bytes)', date('c', $file->time), number_format($file->size)) ?>
</a> </a>
</li> </li>

Loading…
Cancel
Save