初始化
缺陷:主题配色需要优化整体的同风格
This commit is contained in:
@@ -11,6 +11,8 @@ use Illuminate\Support\Facades\Storage;
|
||||
*/
|
||||
class LocalhostStorageService extends BaseNotAuthService implements OssStorageInterface
|
||||
{
|
||||
use ObjectKeyNormalizeTrait;
|
||||
|
||||
protected array $config = [
|
||||
'domain' => '',
|
||||
'path_prefix' => '',
|
||||
@@ -45,6 +47,56 @@ class LocalhostStorageService extends BaseNotAuthService implements OssStorageIn
|
||||
return $this->deleteFile($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫本地磁盘目录
|
||||
*
|
||||
* 本地盘没有 marker 这种服务端游标,用「已列举条数」当偏移量模拟:
|
||||
* 先把文件名排序固定顺序,再按偏移切页,这样反复调用能稳定推进。
|
||||
* 代价是同步期间新增文件会让偏移错位,但素材同步是幂等的,下一轮就自愈。
|
||||
*/
|
||||
public function listObjects(string $prefix = '', string $marker = '', int $limit = 100): array
|
||||
{
|
||||
$listPrefix = rtrim($this->scopedListPrefix($prefix), '/');
|
||||
$offset = max(0, (int) $marker);
|
||||
$files = Storage::allFiles($listPrefix);
|
||||
sort($files);
|
||||
$page = array_slice($files, $offset, $this->boundedLimit($limit));
|
||||
|
||||
$items = [];
|
||||
foreach ($page as $file) {
|
||||
$key = $this->normalizeObjectKey($file);
|
||||
if ($key === '') {
|
||||
continue;
|
||||
}
|
||||
$realPath = Storage::path($file);
|
||||
$items[] = [
|
||||
'key' => $key,
|
||||
'size' => (int) Storage::size($file),
|
||||
// 本地盘没有服务端 ETag,用 md5 顶上,素材库靠它判重与校验
|
||||
'hash' => is_file($realPath) ? (string) md5_file($realPath) : '',
|
||||
'last_modified' => (int) Storage::lastModified($file),
|
||||
'url' => $this->publicUrlOf($key, asset('/storage/' . $key)),
|
||||
];
|
||||
}
|
||||
|
||||
$next = $offset + count($page);
|
||||
$finished = $next >= count($files);
|
||||
return [
|
||||
'items' => $items,
|
||||
'next_marker' => $finished ? '' : (string) $next,
|
||||
'finished' => $finished,
|
||||
];
|
||||
}
|
||||
|
||||
public function deleteObject(string $key): bool
|
||||
{
|
||||
$key = $this->normalizeObjectKey($key);
|
||||
if ($key === '') {
|
||||
return false;
|
||||
}
|
||||
return $this->deleteFile($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入本地 storage;兼容 UploadedFile 与路径字符串
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user