mirror of
https://github.com/Terranom674/Piwigo_Bratonien_Tools.git
synced 2026-09-19 14:04:34 +00:00
0.9.6.29: Shadowtree- und Sync-Umbau zurückrollen
This commit is contained in:
28
runtime/lib/build_webdav_placeholder_source.py
Normal file → Executable file
28
runtime/lib/build_webdav_placeholder_source.py
Normal file → Executable file
@@ -1,9 +1,9 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Build a placeholder-backed local source tree from Nextcloud WebDAV.
|
||||
|
||||
This creates only tiny placeholder files plus a metadata mapping; no Nextcloud
|
||||
original media is downloaded. The authenticated Nextcloud user is never used as
|
||||
an album name. Selecting the user's WebDAV root mirrors its children directly.
|
||||
This is intentionally additive: it does not replace the existing local-storage
|
||||
connector path. It creates only tiny placeholder files plus a metadata mapping;
|
||||
no Nextcloud original media is downloaded.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -26,6 +26,8 @@ from pathlib import Path, PurePosixPath
|
||||
DAV = "DAV:"
|
||||
OC = "http://owncloud.org/ns"
|
||||
SUPPORTED_IMAGE_EXTENSIONS = {".jpg", ".jpeg", ".png", ".gif", ".webp"}
|
||||
# 1x1 transparent GIF, 34 bytes. The filename keeps the remote extension;
|
||||
# the placeholder exists only so Piwigo can discover the logical image entry.
|
||||
PLACEHOLDER = base64.b64decode("R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==")
|
||||
|
||||
|
||||
@@ -146,7 +148,13 @@ def link_placeholder(seed: Path, target: Path) -> None:
|
||||
target.write_bytes(PLACEHOLDER)
|
||||
|
||||
|
||||
def build_root(client: WebDavClient, remote_root: str, local_root: Path, seed: Path, mapping: dict[str, dict[str, object]]) -> tuple[int, int, int]:
|
||||
def build_root(
|
||||
client: WebDavClient,
|
||||
remote_root: str,
|
||||
local_root: Path,
|
||||
seed: Path,
|
||||
mapping: dict[str, dict[str, object]],
|
||||
) -> tuple[int, int, int]:
|
||||
files = 0
|
||||
folders = 0
|
||||
skipped = 0
|
||||
@@ -245,19 +253,17 @@ def main() -> int:
|
||||
mapping: dict[str, dict[str, object]] = {}
|
||||
manifest: list[str] = []
|
||||
total_files = total_folders = total_skipped = 0
|
||||
used_fileids: set[int] = set()
|
||||
used_names: set[str] = set()
|
||||
|
||||
for remote_root_raw in args.root:
|
||||
remote_root = validate_relative(remote_root_raw)
|
||||
current, _ = client.list_collection(remote_root)
|
||||
fileid = int(current["fileid"])
|
||||
if fileid in used_fileids:
|
||||
fail(f"duplicate selected Nextcloud root fileid: {fileid}")
|
||||
used_fileids.add(fileid)
|
||||
# An explicitly selected folder keeps its own name. The authenticated
|
||||
# user's WebDAV root is transparent and must never become an album.
|
||||
display = "" if remote_root == "" else (str(current.get("display_name", "")).strip() or PurePosixPath(remote_root).name)
|
||||
display = str(current.get("display_name", "")).strip() or (PurePosixPath(remote_root).name if remote_root else args.user)
|
||||
local_name = f"root-{fileid}"
|
||||
if local_name in used_names:
|
||||
fail(f"duplicate selected Nextcloud root fileid: {fileid}")
|
||||
used_names.add(local_name)
|
||||
local_root = staging / local_name
|
||||
files, folders, skipped = build_root(client, remote_root, local_root, seed, mapping)
|
||||
total_files += files
|
||||
|
||||
29
runtime/lib/piwigo-sync.php
Normal file → Executable file
29
runtime/lib/piwigo-sync.php
Normal file → Executable file
@@ -252,6 +252,8 @@ try
|
||||
);
|
||||
decode_ws(http_request($base_url.'/ws.php?format=json', array('method'=>'bratonien.nc.syncProductive', 'site_id'=>$site_id), $headers));
|
||||
$orphan = decode_ws(http_request($base_url.'/ws.php?format=json', array('method'=>'bratonien.nc.syncOrphans', 'site_id'=>$site_id, 'simulate'=>0), $headers));
|
||||
// Entfernt alte technische bratonien-webdav-N Wrapper aus Site 1,
|
||||
// nachdem deren generierte Verzeichnisse beim Reconcile entfernt wurden.
|
||||
if ($site_id !== 1)
|
||||
{
|
||||
decode_ws(http_request($base_url.'/ws.php?format=json', array('method'=>'bratonien.nc.syncOrphans', 'site_id'=>1, 'simulate'=>0), $headers));
|
||||
@@ -282,31 +284,16 @@ try
|
||||
try
|
||||
{
|
||||
decode_ws(http_request($base_url.'/ws.php?format=json', array('method'=>'pwg.session.login', 'username'=>$fallback_user, 'password'=>$fallback_password), array(), $cookie_file));
|
||||
|
||||
// Der Fallback darf keinen zweiten Strukturpfad benutzen. Auch mit
|
||||
// Benutzer/Passwort wird exakt derselbe Bratonien-Sync wie mit API-Key
|
||||
// ausgefuehrt. Dadurch werden alte technische WebDAV-Kategorien entfernt
|
||||
// und vorhandene Piwigo-Alben wiederverwendet.
|
||||
decode_ws(http_request(
|
||||
$base_url.'/ws.php?format=json',
|
||||
array('method'=>'bratonien.nc.syncProductive', 'site_id'=>$site_id),
|
||||
http_request(
|
||||
$base_url.'/admin.php?page=site_update&site='.$site_id,
|
||||
array('sync'=>'files','display_info'=>1,'privacy_level'=>0,'sync_meta'=>1,'simulate'=>0,'subcats-included'=>1,'bratonien_connector'=>1,'submit'=>1),
|
||||
array(),
|
||||
$cookie_file
|
||||
));
|
||||
$orphan = decode_ws(http_request(
|
||||
$base_url.'/ws.php?format=json',
|
||||
array('method'=>'bratonien.nc.syncOrphans', 'site_id'=>$site_id, 'simulate'=>0),
|
||||
array(),
|
||||
$cookie_file
|
||||
));
|
||||
);
|
||||
$orphan = decode_ws(http_request($base_url.'/ws.php?format=json', array('method'=>'bratonien.nc.syncOrphans', 'site_id'=>$site_id, 'simulate'=>0), array(), $cookie_file));
|
||||
if ($site_id !== 1)
|
||||
{
|
||||
decode_ws(http_request(
|
||||
$base_url.'/ws.php?format=json',
|
||||
array('method'=>'bratonien.nc.syncOrphans', 'site_id'=>1, 'simulate'=>0),
|
||||
array(),
|
||||
$cookie_file
|
||||
));
|
||||
decode_ws(http_request($base_url.'/ws.php?format=json', array('method'=>'bratonien.nc.syncOrphans', 'site_id'=>1, 'simulate'=>0), array(), $cookie_file));
|
||||
}
|
||||
$added = (int)($orphan['added_orphans'] ?? 0);
|
||||
$deleted = (int)($orphan['deleted_orphans'] ?? 0);
|
||||
|
||||
31
runtime/lib/shadow_tree.py
Normal file → Executable file
31
runtime/lib/shadow_tree.py
Normal file → Executable file
@@ -79,23 +79,15 @@ def preferred_target(source_key: str, raw_name: str, parent_target: Path, old_ma
|
||||
return safe_name(raw_name)
|
||||
|
||||
|
||||
def mirror_directory(
|
||||
source: Path,
|
||||
target: Path,
|
||||
source_key: str,
|
||||
target_key: Path,
|
||||
old_map: dict[str, str],
|
||||
new_map: dict[str, str],
|
||||
used: set[str] | None = None,
|
||||
) -> None:
|
||||
def mirror_directory(source: Path, target: Path, source_key: str, target_key: Path, old_map: dict[str, str], new_map: dict[str, str]) -> None:
|
||||
target.mkdir(parents=True, exist_ok=True)
|
||||
used_names = used if used is not None else set()
|
||||
used: set[str] = set()
|
||||
for child in sorted(source.iterdir(), key=lambda item: (item.name.casefold(), item.name)):
|
||||
if child.is_symlink():
|
||||
continue
|
||||
child_source_key = f"{source_key}/{child.name}"
|
||||
preferred = preferred_target(child_source_key, child.name, target_key, old_map)
|
||||
child_name = unique_name(preferred, used_names, child.is_file())
|
||||
child_name = unique_name(preferred, used, child.is_file())
|
||||
child_target = target / child_name
|
||||
child_target_key = target_key / child_name
|
||||
new_map[child_source_key] = child_target_key.as_posix()
|
||||
@@ -128,26 +120,11 @@ def build(manifest: Path, destination: Path, state_file: Path) -> None:
|
||||
|
||||
try:
|
||||
used_roots: set[str] = set()
|
||||
transparent_roots = 0
|
||||
for entry in sorted(entries, key=lambda item: (item["display_name"].casefold(), item["share_id"])):
|
||||
source = Path(entry["source_path"])
|
||||
source_key = f"share:{entry['share_id']}"
|
||||
is_file_share = entry["item_type"] == "file"
|
||||
|
||||
# Empty display_name is intentional: it represents the authenticated
|
||||
# user's WebDAV root. Its children belong directly at destination;
|
||||
# the Nextcloud username must never become an album wrapper.
|
||||
if not is_file_share and entry["display_name"] == "":
|
||||
transparent_roots += 1
|
||||
if transparent_roots > 1:
|
||||
raise ValueError("only one transparent WebDAV root is allowed")
|
||||
if not source.is_dir():
|
||||
raise FileNotFoundError(f"source is not a readable directory: {source}")
|
||||
new_map[source_key] = "."
|
||||
mirror_directory(source, staging, source_key, Path("."), old_map, new_map, used_roots)
|
||||
continue
|
||||
|
||||
preferred = preferred_target(source_key, entry["display_name"], Path("."), old_map)
|
||||
is_file_share = entry["item_type"] == "file"
|
||||
root_name = unique_name(preferred, used_roots, is_file_share)
|
||||
root_key = Path(root_name)
|
||||
new_map[source_key] = root_key.as_posix()
|
||||
|
||||
Reference in New Issue
Block a user