From 026735489977fabc1b837d854429b277d4bf19bb Mon Sep 17 00:00:00 2001 From: jmbardallo Date: Mon, 27 Jul 2026 13:40:34 +0200 Subject: [PATCH 1/6] Optimize mktorrent piece size calculation --- CHANGELOG.md | 6 ++++++ bin/createTorrentSum.py | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37eaf86..3dbaa28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.10.6] - 2026-07-27 + +### Changed + +- **createTorrentSum**: Optimizada la creación de ficheros torrent (`mktorrent`) calculando el tamaño de pieza (`-l`) de forma dinámica según el tamaño de la imagen, evitando archivos `.torrent` con cientos de miles de piezas que saturaban el tracker en imágenes muy grandes. + ## [0.10.5] - 2026-04-14 ### Fixed diff --git a/bin/createTorrentSum.py b/bin/createTorrentSum.py index 5be3a85..edb68cd 100644 --- a/bin/createTorrentSum.py +++ b/bin/createTorrentSum.py @@ -134,8 +134,18 @@ def create_torrent(file_path, torrent_file, datafullsum): repo_ip = get_IPlocal() tracker_url = f"http://{repo_ip}:6969/announce" + import math + file_size = os.path.getsize(file_path) + target_pieces = 100000 + piece_size_target = file_size / target_pieces + if piece_size_target <= 262144: + l_val = 18 + else: + l_val = math.ceil(math.log(piece_size_target, 2)) + l_val = max(18, min(26, l_val)) + # Creamos una litas para ejecutar el comando mktorrent para crear el archivo torrent - splitted_cmd = f"nice -n 0 mktorrent -a {tracker_url} -c {datafullsum} -o {torrent_file} {file_path}".split() + splitted_cmd = f"nice -n 0 mktorrent -l {l_val} -a {tracker_url} -c {datafullsum} -o {torrent_file} {file_path}".split() print(f"Sending command: {' '.join(splitted_cmd)}") # Ejecutamos el comando en el sistema, e imprimimos el resultado: -- 2.40.1 From e6644191c1ef86768d4177dcd7a6d47aa21e1771 Mon Sep 17 00:00:00 2001 From: jmbardallo Date: Tue, 28 Jul 2026 10:47:23 +0200 Subject: [PATCH 2/6] Feat(ogrepository): implement forgejo git repository deletion endpoint --- api/repo_api.py | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/api/repo_api.py b/api/repo_api.py index f597715..5f5ede8 100644 --- a/api/repo_api.py +++ b/api/repo_api.py @@ -2288,6 +2288,31 @@ def git_forgejo_create_repo(repo): "private" : False }) +def git_forgejo_delete_command(url): + token = "" + with open("/opt/opengnsys/etc/ogGitApiToken.cfg", "r", encoding='utf-8') as token_file: + token = token_file.read().strip() + + if url[0] == "/": + url = url[1:] + + url = f"http://localhost:{OGGIT_FORGEJO_PORT}/{url}" + + journal.send(f"Executing forgejo DELETE to {url}...", PRIORITY=journal.LOG_DEBUG, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") + + r = requests.delete( + url, + headers = { 'Authorization' : f"token {token}" }, + timeout = 60 + ) + + journal.send(f"Request status was {r.status_code}, content {r.content}", PRIORITY=journal.LOG_DEBUG, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") + + return r.status_code, r.content.decode('utf-8') + +def git_forgejo_delete_repo(repo): + return git_forgejo_delete_command(f"/api/v1/repos/oggit/{repo}") + def git_forgejo_create_tag(repo,tag,msg,target): return git_forgejo_post_command(f"/api/v1/repos/oggit/{repo}/tags", { "message": msg, @@ -2453,9 +2478,23 @@ def git_create_repository(): return jsonify({"status": "Repository created"}), 201 -@app.route("/ogrepository/v1/git/repositories", methods=['DELETE']) -def git_delete_repository(): - return jsonify({"error" : "Not implemented"}), 500 +@app.route("/ogrepository/v1/git/repositories/", methods=['DELETE']) +def git_delete_repository(repo): + repo_path = os.path.join(REPOSITORIES_BASE_PATH, OGGIT_USER, repo + ".git") + + status, content = git_forgejo_delete_repo(repo) + if status not in (204, 404): + journal.send(f"Can't delete repository {repo} from forgejo: {content}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") + return jsonify({"error" : f"Failed to delete from forgejo: {content}"}), 500 + + if os.path.isdir(repo_path): + import shutil + shutil.rmtree(repo_path, ignore_errors=True) + journal.send(f"Repository {repo} deleted", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") + return jsonify({"status": "Repository deleted"}), 200 + else: + journal.send(f"Can't delete repository {repo}, not found at {repo_path}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") + return jsonify({"status": "Repository not found"}), 404 @app.route("/ogrepository/v1/git/repositories//sync", methods=['POST']) def git_sync_repository(repo): -- 2.40.1 From 4957129463bcdc6eb23f3a16c90486c831d25499 Mon Sep 17 00:00:00 2001 From: jmbardallo Date: Tue, 28 Jul 2026 12:32:41 +0200 Subject: [PATCH 3/6] Docs: update CHANGELOG for git repository deletion API --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3dbaa28..ae4d706 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [0.10.6] - 2026-07-27 +### Added +- API de Repositorios Git (`repo_api.py`): Implementado el endpoint `DELETE /ogrepository/v1/git/repositories/` que sustituye al antiguo código "Not implemented". Ahora se encarga de eliminar el repositorio correctamente de la base de datos de Forgejo y de purgar el directorio `.git` del disco duro. + ### Changed - **createTorrentSum**: Optimizada la creación de ficheros torrent (`mktorrent`) calculando el tamaño de pieza (`-l`) de forma dinámica según el tamaño de la imagen, evitando archivos `.torrent` con cientos de miles de piezas que saturaban el tracker en imágenes muy grandes. -- 2.40.1 From 2a49259f7276ff63ce5f30034c3c68aa756d33b2 Mon Sep 17 00:00:00 2001 From: jmbardallo Date: Tue, 28 Jul 2026 12:48:52 +0200 Subject: [PATCH 4/6] Fix(ogrepository): make git repo deletion idempotent --- api/repo_api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/repo_api.py b/api/repo_api.py index 5f5ede8..4642209 100644 --- a/api/repo_api.py +++ b/api/repo_api.py @@ -2493,8 +2493,8 @@ def git_delete_repository(repo): journal.send(f"Repository {repo} deleted", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") return jsonify({"status": "Repository deleted"}), 200 else: - journal.send(f"Can't delete repository {repo}, not found at {repo_path}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") - return jsonify({"status": "Repository not found"}), 404 + journal.send(f"Repository {repo} already deleted or not found at {repo_path}", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG") + return jsonify({"status": "Repository already deleted"}), 200 @app.route("/ogrepository/v1/git/repositories//sync", methods=['POST']) def git_sync_repository(repo): -- 2.40.1 From 050a69ed6511ab3f6303feafb1d8a66858285446 Mon Sep 17 00:00:00 2001 From: jmbardallo Date: Wed, 29 Jul 2026 09:31:08 +0200 Subject: [PATCH 5/6] Perf(ogrepository): increase target_pieces for torrent creation to cap piece size at 2MB for images up to 400GB --- bin/createTorrentSum.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/createTorrentSum.py b/bin/createTorrentSum.py index edb68cd..766f53e 100644 --- a/bin/createTorrentSum.py +++ b/bin/createTorrentSum.py @@ -136,7 +136,7 @@ def create_torrent(file_path, torrent_file, datafullsum): import math file_size = os.path.getsize(file_path) - target_pieces = 100000 + target_pieces = 200000 piece_size_target = file_size / target_pieces if piece_size_target <= 262144: l_val = 18 -- 2.40.1 From 6215f3d01b8e9762646c8fc1731afffc6018795e Mon Sep 17 00:00:00 2001 From: jmbardallo Date: Wed, 29 Jul 2026 09:31:32 +0200 Subject: [PATCH 6/6] Docs: update CHANGELOG for 2MB target pieces fix --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae4d706..f59dc8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- **createTorrentSum**: Optimizada la creación de ficheros torrent (`mktorrent`) calculando el tamaño de pieza (`-l`) de forma dinámica según el tamaño de la imagen, evitando archivos `.torrent` con cientos de miles de piezas que saturaban el tracker en imágenes muy grandes. +- **createTorrentSum**: Optimizada la creación de ficheros torrent (`mktorrent`) calculando el tamaño de pieza (`-l`) de forma dinámica según el tamaño de la imagen, evitando archivos `.torrent` con cientos de miles de piezas que saturaban el tracker en imágenes muy grandes. Se ha incrementado `target_pieces` a 200.000 para garantizar que las piezas no superen los 2 MB en imágenes de hasta 400 GB. ## [0.10.5] - 2026-04-14 -- 2.40.1