1+ /**
2+ * Utilities for reading git-annex metadata
3+ */
14import { dirname , join , parse , SEPARATOR_PATTERN } from '@std/path'
25import { default as git } from 'isomorphic-git'
36import { createMD5 } from 'hash-wasm'
@@ -24,18 +27,6 @@ export async function readAnnexPath(
2427 return textDecoder . decode ( blob )
2528}
2629
27- // Logic
28- //
29- // stat file
30- // if found:
31- // use local opener
32- // if not:
33- // readlink -> (../)*.git/annex/objects/*/*/{key}/{key}
34- // determine git root
35- // load remotes by UUID (git-annex:remote.log)
36- // read rmet (git-annex:{md5(key)[0:3]}/{md5(key)[3:6]}/{key}.log.rmet)
37- // Construct URL
38-
3930/**
4031 * git-annex hashDirLower implementation based on https://git-annex.branchable.com/internals/hashing/
4132 * Compute the directory path from a git-annex filename
@@ -93,6 +84,9 @@ export async function readRemotes(options: any): Promise<Record<string, Record<s
9384 return byUUID
9485}
9586
87+ /**
88+ * Resolve an annexed file location to an HTTP URL, if a public S3 remote is available
89+ */
9690export async function resolveAnnexedFile (
9791 path : string ,
9892 remote ?: string ,
@@ -116,6 +110,11 @@ export async function resolveAnnexedFile(
116110 if ( remote ) {
117111 let matching : string | undefined
118112 for ( const [ u , r ] of Object . entries ( remotes ) ) {
113+ // Only consider public S3 remotes.
114+ // This will need to be expanded for other types of remotes in future
115+ if ( ! r ?. publicurl ) {
116+ continue
117+ }
119118 if ( r . name === remote ) {
120119 matching = u
121120 break
@@ -130,8 +129,12 @@ export async function resolveAnnexedFile(
130129 uuid = Object . entries ( rmet ) . toSorted ( ( a , b ) => + b [ 1 ] . timestamp - + a [ 1 ] . timestamp ) [ 0 ] [ 0 ]
131130 }
132131 const { publicurl } = remotes [ uuid ]
133- const metadata = rmet [ uuid ]
134132
133+ if ( ! publicurl ) {
134+ throw new Error ( `No publicurl found for remote ${ uuid } ` )
135+ }
136+
137+ const metadata = rmet [ uuid ]
135138 const url = `${ publicurl } /${ metadata . path } ?versionId=${ metadata . version } `
136139
137140 return { url, size }
0 commit comments