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

Method getAuthFileLinkRecord

src/FileRise/Domain/FileModel.php:2941–2999  ·  view source on GitHub ↗
(string $token)

Source from the content-addressed store, hash-verified

2939 }
2940
2941 public static function getAuthFileLinkRecord(string $token): ?array
2942 {
2943 $token = strtolower(trim($token));
2944 if (!preg_match('/^[a-f0-9]{64}$/', $token)) {
2945 return null;
2946 }
2947
2948 $now = time();
2949 $readRecord = function (string $metaRoot, string $fallbackSourceId) use ($token, $now): ?array {
2950 $path = self::authFileLinksPathForMetaRoot($metaRoot);
2951 if (!is_file($path)) {
2952 return null;
2953 }
2954
2955 $links = self::readAuthFileLinks($path);
2956 $cleaned = self::cleanAuthFileLinks($links, $now);
2957 if ($cleaned !== $links) {
2958 @file_put_contents($path, json_encode($cleaned, JSON_PRETTY_PRINT), LOCK_EX);
2959 }
2960 if (!isset($cleaned[$token]) || !is_array($cleaned[$token])) {
2961 return null;
2962 }
2963
2964 $record = $cleaned[$token];
2965 $recordSourceId = trim((string)($record['sourceId'] ?? ''));
2966 if ($recordSourceId === '') {
2967 $record['sourceId'] = $fallbackSourceId;
2968 }
2969 return $record;
2970 };
2971
2972 $currentId = class_exists('SourceContext') ? SourceContext::getActiveId() : '';
2973 $record = $readRecord(self::metaRoot(), $currentId);
2974 if ($record) {
2975 return $record;
2976 }
2977
2978 if (!class_exists('SourceContext') || !SourceContext::sourcesEnabled()) {
2979 return null;
2980 }
2981
2982 $sources = SourceContext::listAllSources();
2983 foreach ($sources as $src) {
2984 if (isset($src['enabled']) && !$src['enabled']) {
2985 continue;
2986 }
2987 $id = (string)($src['id'] ?? '');
2988 if ($id === '' || $id === $currentId) {
2989 continue;
2990 }
2991
2992 $record = $readRecord(SourceContext::metaRootForId($id), $id);
2993 if ($record) {
2994 return $record;
2995 }
2996 }
2997
2998 return null;

Callers 1

resolveAuthFileLinkMethod · 0.80

Calls 8

readAuthFileLinksMethod · 0.95
cleanAuthFileLinksMethod · 0.95
metaRootMethod · 0.95
getActiveIdMethod · 0.80
listAllSourcesMethod · 0.80
sourcesEnabledMethod · 0.45
metaRootForIdMethod · 0.45

Tested by

no test coverage detected