fix: accept gitea content entries
This commit is contained in:
+25
-11
@@ -156,22 +156,34 @@ function parseLfsPointer(content: string): { oid: string; size: number } | null
|
|||||||
interface GitContentEntry {
|
interface GitContentEntry {
|
||||||
content?: string
|
content?: string
|
||||||
name: string
|
name: string
|
||||||
path: string
|
path?: string
|
||||||
sha: string
|
sha?: string
|
||||||
size: number
|
size?: number
|
||||||
type?: string
|
type?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
function isGitContentEntry(value: unknown): value is GitContentEntry {
|
function isGitContentEntry(value: unknown): value is GitContentEntry {
|
||||||
return isRecord(value)
|
return isRecord(value)
|
||||||
&& typeof value.name === 'string'
|
&& typeof value.name === 'string'
|
||||||
&& typeof value.path === 'string'
|
&& (value.path === undefined || typeof value.path === 'string')
|
||||||
&& typeof value.sha === 'string'
|
&& (value.sha === undefined || typeof value.sha === 'string')
|
||||||
&& typeof value.size === 'number'
|
&& (value.size === undefined || typeof value.size === 'number')
|
||||||
&& (value.content === undefined || typeof value.content === 'string')
|
&& (value.content === undefined || typeof value.content === 'string')
|
||||||
&& (value.type === undefined || typeof value.type === 'string')
|
&& (value.type === undefined || typeof value.type === 'string')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getContentEntrySize(entry: GitContentEntry) {
|
||||||
|
return entry.size ?? 0
|
||||||
|
}
|
||||||
|
|
||||||
|
function getRequiredContentEntrySha(entry: GitContentEntry, path: string) {
|
||||||
|
if (!entry.sha) {
|
||||||
|
throw new Error(`SHA Git manquant pour ${path}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
return entry.sha
|
||||||
|
}
|
||||||
|
|
||||||
function decodeBase64Content(content: string) {
|
function decodeBase64Content(content: string) {
|
||||||
return Buffer.from(content.replace(/\s/g, ''), 'base64').toString('utf-8')
|
return Buffer.from(content.replace(/\s/g, ''), 'base64').toString('utf-8')
|
||||||
}
|
}
|
||||||
@@ -428,7 +440,7 @@ async function pushAllToGitea(
|
|||||||
content: file.contentBase64,
|
content: file.contentBase64,
|
||||||
operation: existing ? 'update' : 'create',
|
operation: existing ? 'update' : 'create',
|
||||||
path: file.path,
|
path: file.path,
|
||||||
sha: existing?.sha,
|
sha: existing ? getRequiredContentEntrySha(existing, file.path) : undefined,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -441,7 +453,7 @@ async function pushAllToGitea(
|
|||||||
operations.push({
|
operations.push({
|
||||||
operation: 'delete',
|
operation: 'delete',
|
||||||
path,
|
path,
|
||||||
sha: existing.sha,
|
sha: getRequiredContentEntrySha(existing, path),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -480,8 +492,10 @@ export async function getRemoteFolder(
|
|||||||
throw new Error(`Reponse Git invalide pour ${folderPath}`)
|
throw new Error(`Reponse Git invalide pour ${folderPath}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isLfsFile(f.name) || f.size > 1024) {
|
const size = getContentEntrySize(f)
|
||||||
return { name: f.name, size: f.size }
|
|
||||||
|
if (!isLfsFile(f.name) || size > 1024) {
|
||||||
|
return { name: f.name, size }
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -498,7 +512,7 @@ export async function getRemoteFolder(
|
|||||||
if (!isHttpError(err) || err.status !== 404) throw err
|
if (!isHttpError(err) || err.status !== 404) throw err
|
||||||
}
|
}
|
||||||
|
|
||||||
return { name: f.name, size: f.size }
|
return { name: f.name, size }
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user