mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-11-16 12:10:29 +03:00
Addition of IPFS CIDv1 to Index
IPFS CIDv1 is only generated for APKs and "repo files"
This commit is contained in:
parent
5e31f23a96
commit
0ad45a94a8
10 changed files with 60 additions and 6 deletions
|
|
@ -4118,6 +4118,25 @@ def run_yamllint(path, indent=0):
|
|||
return '\n'.join(result)
|
||||
|
||||
|
||||
def calculate_IPFS_cid(filename):
|
||||
"""
|
||||
Calculate the IPFS CID of a file and add it to the index.
|
||||
|
||||
uses ipfs_cid package at https://packages.debian.org/sid/ipfs-cid
|
||||
Returns CIDv1 of a file as per IPFS recommendation
|
||||
"""
|
||||
exe_name = 'ipfs_cid'
|
||||
if not set_command_in_config(exe_name) or not config.get(exe_name):
|
||||
logging.info(_("%s not found, skipping CIDv1 generation") % exe_name)
|
||||
return
|
||||
file_cid = subprocess.run([config[exe_name], filename], capture_output=True)
|
||||
|
||||
if file_cid.returncode == 0:
|
||||
cid_output = file_cid.stdout.decode()
|
||||
cid_output_dict = json.loads(cid_output)
|
||||
return cid_output_dict['CIDv1']
|
||||
|
||||
|
||||
def sha256sum(filename):
|
||||
"""Calculate the sha256 of the given file."""
|
||||
sha = hashlib.sha256()
|
||||
|
|
|
|||
|
|
@ -607,6 +607,10 @@ def convert_version(version, app, repodir):
|
|||
"size": version["size"]
|
||||
}
|
||||
|
||||
ipfsCIDv1 = version.get("ipfsCIDv1")
|
||||
if ipfsCIDv1:
|
||||
ver["file"]["ipfsCIDv1"] = ipfsCIDv1
|
||||
|
||||
if "srcname" in version:
|
||||
ver["src"] = file_entry(os.path.join(repodir, version["srcname"]))
|
||||
|
||||
|
|
@ -945,7 +949,7 @@ def make_v1(apps, packages, repodir, repodict, requestsdict, fdroid_signing_key_
|
|||
for k, v in sorted(package.items()):
|
||||
if not v:
|
||||
continue
|
||||
if k in ('icon', 'icons', 'icons_src', 'name', ):
|
||||
if k in ('icon', 'icons', 'icons_src', 'ipfsCIDv1', 'name'):
|
||||
continue
|
||||
d[k] = v
|
||||
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ if hasattr(Image, 'DecompressionBombWarning'):
|
|||
warnings.simplefilter('error', Image.DecompressionBombWarning)
|
||||
Image.MAX_IMAGE_PIXELS = 0xffffff # 4096x4096
|
||||
|
||||
METADATA_VERSION = 20001
|
||||
METADATA_VERSION = 20002
|
||||
|
||||
# less than the valid range of versionCode, i.e. Java's Integer.MIN_VALUE
|
||||
UNSET_VERSION_CODE = -0x100000000
|
||||
|
|
@ -1148,6 +1148,7 @@ def scan_repo_files(apkcache, repodir, knownapks, use_date_from_file=False):
|
|||
repo_file['apkName'] = name_utf8
|
||||
repo_file['hash'] = shasum
|
||||
repo_file['hashType'] = 'sha256'
|
||||
repo_file['ipfsCIDv1'] = common.calculate_IPFS_cid(name_utf8)
|
||||
repo_file['versionCode'] = 0
|
||||
repo_file['versionName'] = shasum[0:7]
|
||||
# the static ID is the SHA256 unless it is set in the metadata
|
||||
|
|
@ -1212,6 +1213,9 @@ def scan_apk(apk_file, require_signature=True):
|
|||
'icons': {},
|
||||
'antiFeatures': set(),
|
||||
}
|
||||
ipfsCIDv1 = common.calculate_IPFS_cid(apk_file)
|
||||
if ipfsCIDv1:
|
||||
apk['ipfsCIDv1'] = ipfsCIDv1
|
||||
|
||||
scan_apk_androguard(apk, apk_file)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue