MCPcopy Create free account
hub / github.com/error311/FileRise / cleanAuthFileLinks

Method cleanAuthFileLinks

src/FileRise/Domain/FileModel.php:2822–2878  ·  view source on GitHub ↗
(array $links, int $now)

Source from the content-addressed store, hash-verified

2820 }
2821
2822 private static function cleanAuthFileLinks(array $links, int $now): array
2823 {
2824 $cleaned = [];
2825 foreach ($links as $token => $record) {
2826 $token = strtolower(trim((string)$token));
2827 if (!preg_match('/^[a-f0-9]{64}$/', $token)) {
2828 continue;
2829 }
2830 if (!is_array($record)) {
2831 continue;
2832 }
2833
2834 $folder = trim((string)($record['folder'] ?? 'root'));
2835 if ($folder === '' || strtolower($folder) === 'root') {
2836 $folder = 'root';
2837 } elseif (!preg_match(REGEX_FOLDER_NAME, $folder)) {
2838 continue;
2839 }
2840
2841 $file = basename(trim((string)($record['file'] ?? '')));
2842 if ($file === '' || !preg_match(REGEX_FILE_NAME, $file)) {
2843 continue;
2844 }
2845
2846 $expiresAt = isset($record['expiresAt']) ? (int)$record['expiresAt'] : 0;
2847 if ($expiresAt > 0 && $expiresAt <= $now) {
2848 continue;
2849 }
2850
2851 $sourceId = trim((string)($record['sourceId'] ?? ''));
2852 if ($sourceId !== '' && !preg_match('/^[A-Za-z0-9_-]{1,64}$/', $sourceId)) {
2853 $sourceId = '';
2854 }
2855
2856 $createdBy = trim((string)($record['createdBy'] ?? ''));
2857 $createdBy = preg_replace('/[\x00-\x1F\x7F]/', '', $createdBy);
2858 $createdAt = isset($record['createdAt']) ? (int)$record['createdAt'] : $now;
2859 if ($createdAt <= 0) {
2860 $createdAt = $now;
2861 }
2862
2863 $cleanRecord = [
2864 'folder' => $folder,
2865 'file' => $file,
2866 'path' => ($folder === 'root') ? $file : ($folder . '/' . $file),
2867 'sourceId' => $sourceId,
2868 'createdBy' => is_string($createdBy) ? $createdBy : '',
2869 'createdAt' => $createdAt,
2870 ];
2871 if ($expiresAt > 0) {
2872 $cleanRecord['expiresAt'] = $expiresAt;
2873 }
2874
2875 $cleaned[$token] = $cleanRecord;
2876 }
2877 return $cleaned;
2878 }
2879

Callers 2

createAuthFileLinkMethod · 0.95
getAuthFileLinkRecordMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected