Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .codacy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
exclude_paths:
- "Core/Configs/AppSecrets.cs"
4 changes: 2 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
**/.dockerignore
**/.dockerignore
**/.env
**/.git
**/.gitignore
Expand All @@ -22,4 +22,4 @@
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
README.md
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* text=auto eol=lf
*.dll binary
*.pdb binary
*.png binary
*.ttf binary
File renamed without changes.
6 changes: 6 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sdk": {
"version": "10.0.100",
"rollForward": "latestFeature"
}
}
90 changes: 90 additions & 0 deletions scripts/fetch-epubsharp.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
param(
[string] $Repo = "L34T/EpubSharp_Elib2Ebook",
[string] $Tag = "",
[string] $OutDir = "Core/External",
[switch] $Force
)

$ErrorActionPreference = "Stop"

function Get-LatestRelease {
param([string] $repo)

$headers = @{
"Accept" = "application/vnd.github+json"
"User-Agent" = "Elib2Ebook-fetch-epubsharp"
}

return Invoke-RestMethod -Headers $headers -Uri ("https://api.github.com/repos/{0}/releases/latest" -f $repo)
}

function Get-ReleaseByTag {
param([string] $repo, [string] $tag)

$headers = @{
"Accept" = "application/vnd.github+json"
"User-Agent" = "Elib2Ebook-fetch-epubsharp"
}

return Invoke-RestMethod -Headers $headers -Uri ("https://api.github.com/repos/{0}/releases/tags/{1}" -f $repo, $tag)
}

function Ensure-Dir {
param([string] $path)
if (-not (Test-Path -LiteralPath $path)) {
New-Item -ItemType Directory -Path $path | Out-Null
}
}

function Download-Asset {
param(
[string] $url,
[string] $path,
[switch] $force
)

if (-not $force -and (Test-Path -LiteralPath $path) -and ((Get-Item -LiteralPath $path).Length -gt 0)) {
Write-Host ("Skip (exists): {0}" -f $path)
return
}

Write-Host ("Download: {0}" -f $path)
Invoke-WebRequest -Uri $url -OutFile $path -UseBasicParsing | Out-Null
}

if ([string]::IsNullOrWhiteSpace($Tag)) {
$release = Get-LatestRelease -repo $Repo
}
else {
$release = Get-ReleaseByTag -repo $Repo -tag $Tag
}

if ($null -eq $release -or [string]::IsNullOrWhiteSpace($release.tag_name)) {
throw "Unable to resolve release for repo '$Repo' tag '$Tag'."
}

$resolvedTag = $release.tag_name
Write-Host ("Using release tag: {0}" -f $resolvedTag)

Ensure-Dir -path $OutDir

$required = @{
"EpubSharp-net10.dll" = "EpubSharp.dll"
"EpubSharp-net10.pdb" = "EpubSharp.pdb"
"EpubSharp-net10.deps.json" = "EpubSharp.deps.json"
}

foreach ($item in $required.GetEnumerator()) {
$assetName = $item.Key
$destName = $item.Value
$asset = $release.assets | Where-Object { $_.name -eq $assetName } | Select-Object -First 1
if ($null -eq $asset -or [string]::IsNullOrWhiteSpace($asset.browser_download_url)) {
throw "Missing asset '$assetName' in release '$resolvedTag' for repo '$Repo'."
}

$dest = Join-Path $OutDir $destName
Download-Asset -url $asset.browser_download_url -path $dest -force:$Force
}

Write-Host "Done."

70 changes: 70 additions & 0 deletions scripts/fetch-epubsharp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env bash
set -euo pipefail

REPO="${EPUBSHARP_REPO:-L34T/EpubSharp_Elib2Ebook}"
TAG="${EPUBSHARP_TAG:-}"
OUTDIR="${EPUBSHARP_OUTDIR:-Core/External}"
FORCE="${EPUBSHARP_FORCE:-0}"

api() {
local url="$1"
curl -fsSL \
-H "Accept: application/vnd.github+json" \
-H "User-Agent: Elib2Ebook-fetch-epubsharp" \
"$url"
}

if [[ -z "${TAG}" ]]; then
release_json="$(api "https://api.github.com/repos/${REPO}/releases/latest")"
else
release_json="$(api "https://api.github.com/repos/${REPO}/releases/tags/${TAG}")"
fi

resolved_tag="$(
python3 -c 'import json,sys; obj=json.load(sys.stdin); print(obj.get("tag_name",""))' <<<"${release_json}"
)"

if [[ -z "${resolved_tag}" ]]; then
echo "Failed to resolve release tag for repo '${REPO}'." >&2
exit 1
fi

echo "Using release tag: ${resolved_tag}"
mkdir -p "${OUTDIR}"

download_url_for() {
local asset_name="$1"
python3 -c '
import json,sys
name=sys.argv[1]
obj=json.load(sys.stdin)
for a in obj.get("assets",[]):
if a.get("name")==name:
print(a.get("browser_download_url",""))
sys.exit(0)
sys.exit(1)
' "${asset_name}" <<<"${release_json}"
}

download() {
local url="$1"
local dest="$2"
if [[ "${FORCE}" != "1" && -s "${dest}" ]]; then
echo "Skip (exists): ${dest}"
return 0
fi
echo "Download: ${dest}"
curl -fsSL -o "${dest}" "${url}"
}

for suffix in dll pdb deps.json; do
asset_name="EpubSharp-net10.${suffix}"
url="$(download_url_for "${asset_name}")"
if [[ -z "${url}" ]]; then
echo "Missing asset '${asset_name}' in release '${resolved_tag}' for repo '${REPO}'." >&2
exit 1
fi
download "${url}" "${OUTDIR}/EpubSharp.${suffix}"
done

echo "Done."