feat(sync): le PC accepte l'adresse du depot (github.com/O/R.git, Gitea) et la convertit en URL d'API
Garde : un dernier segment qui ressemble a un fichier (.json) reste une URL WebDAV. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
+2
-2
@@ -857,9 +857,9 @@
|
|||||||
</label>
|
</label>
|
||||||
<div id="syncConfig" style="display:none;border-left:2px solid var(--border);padding-left:10px;margin-left:4px">
|
<div id="syncConfig" style="display:none;border-left:2px solid var(--border);padding-left:10px;margin-left:4px">
|
||||||
<div style="margin-bottom:6px">
|
<div style="margin-bottom:6px">
|
||||||
<div style="font-size:11px;color:var(--text-faint);margin-bottom:4px">URL — full path to the snapshot file, or a Gitea contents path</div>
|
<div style="font-size:11px;color:var(--text-faint);margin-bottom:4px">URL — the repository address (github.com/you/repo.git or your Gitea), or a WebDAV file URL</div>
|
||||||
<input type="text" id="syncUrl" class="so-input"
|
<input type="text" id="syncUrl" class="so-input"
|
||||||
placeholder="https://git.example.com/api/v1/repos/OWNER/REPO/contents/vault-sync.json"
|
placeholder="https://github.com/you/repo.git"
|
||||||
style="width:100%;font-size:12px">
|
style="width:100%;font-size:12px">
|
||||||
</div>
|
</div>
|
||||||
<div style="display:flex;gap:8px;margin-bottom:6px">
|
<div style="display:flex;gap:8px;margin-bottom:6px">
|
||||||
|
|||||||
@@ -8221,8 +8221,17 @@ async function init() {
|
|||||||
if (syncCfgBox) syncCfgBox.style.display = on ? '' : 'none';
|
if (syncCfgBox) syncCfgBox.style.display = on ? '' : 'none';
|
||||||
toast(on ? 'Sync enabled' : 'Sync disabled');
|
toast(on ? 'Sync enabled' : 'Sync disabled');
|
||||||
});
|
});
|
||||||
if (syncUrlEl) syncUrlEl.addEventListener('change', e =>
|
// L'adresse du depot suffit (github.com/O/R.git, Gitea) : elle est
|
||||||
Bridge.setPref(SYNC_PREFS.url, e.target.value.trim()));
|
// convertie en URL d'API, et le champ montre ce qui est enregistre.
|
||||||
|
if (syncUrlEl) syncUrlEl.addEventListener('change', e => {
|
||||||
|
const raw = e.target.value.trim();
|
||||||
|
const url = syncNormalizeRepoUrl(raw);
|
||||||
|
if (url !== raw) {
|
||||||
|
e.target.value = url;
|
||||||
|
toast('Repository address converted to its API URL');
|
||||||
|
}
|
||||||
|
Bridge.setPref(SYNC_PREFS.url, url);
|
||||||
|
});
|
||||||
if (syncUserEl) syncUserEl.addEventListener('change', e =>
|
if (syncUserEl) syncUserEl.addEventListener('change', e =>
|
||||||
Bridge.setPref(SYNC_PREFS.user, e.target.value.trim()));
|
Bridge.setPref(SYNC_PREFS.user, e.target.value.trim()));
|
||||||
if (syncPwdEl) syncPwdEl.addEventListener('change', e =>
|
if (syncPwdEl) syncPwdEl.addEventListener('change', e =>
|
||||||
|
|||||||
@@ -90,6 +90,25 @@ function syncIsGitea(url) {
|
|||||||
return u.includes('/api/v1/repos/') || u.includes('api.github.com/repos/');
|
return u.includes('/api/v1/repos/') || u.includes('api.github.com/repos/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ADRESSE DU DEPOT TELLE QUE LE NAVIGATEUR (OU "git clone") LA DONNE.
|
||||||
|
// https://github.com/O/R(.git) -> API de GitHub ; https://hote/O/R(.git) -> API
|
||||||
|
// de Gitea. Fichier par defaut vault-sync.json, ou celui d'un lien .../blob/B/F
|
||||||
|
// (GitHub) ou .../src/branch/B/F (Gitea). Tout le reste passe tel quel - une
|
||||||
|
// URL WebDAV, une URL d'API deja complete. GARDE : un dernier segment qui a
|
||||||
|
// l'air d'un fichier (.json...) n'est pas un depot - sinon
|
||||||
|
// https://serveur/webdav/vault.json deviendrait une API Gitea imaginaire.
|
||||||
|
function syncNormalizeRepoUrl(u) {
|
||||||
|
u = (u || '').replace(/\s+/g, '');
|
||||||
|
if (!u || syncIsGitea(u)) return u;
|
||||||
|
const g = u.match(/^https?:\/\/(www\.)?github\.com\/([^\/]+)\/([^\/]+?)(?:\.git)?(?:\/blob\/[^\/]+\/(.+?))?\/?$/i);
|
||||||
|
if (g) return 'https://api.github.com/repos/' + g[2] + '/' + g[3] +
|
||||||
|
'/contents/' + (g[4] || 'vault-sync.json');
|
||||||
|
const m = u.match(/^(https?:\/\/[^\/]+)\/([^\/]+)\/([^\/]+?)(\.git)?(?:\/src\/branch\/[^\/]+\/(.+?))?\/?$/i);
|
||||||
|
if (!m) return u;
|
||||||
|
if (!m[4] && !m[5] && /\.[a-z0-9]{2,5}$/i.test(m[3])) return u; // un fichier, pas un depot
|
||||||
|
return m[1] + '/api/v1/repos/' + m[2] + '/' + m[3] + '/contents/' + (m[5] || 'vault-sync.json');
|
||||||
|
}
|
||||||
|
|
||||||
// UN DEPOT PUBLIC EST REFUSE. Chaque synchro est un commit : l'historique garde
|
// UN DEPOT PUBLIC EST REFUSE. Chaque synchro est un commit : l'historique garde
|
||||||
// tous les instantanes, chacun attaquable hors ligne par qui peut les lire.
|
// tous les instantanes, chacun attaquable hors ligne par qui peut les lire.
|
||||||
// '' = prive ou impossible a savoir (on ne bloque pas sur un doute reseau).
|
// '' = prive ou impossible a savoir (on ne bloque pas sur un doute reseau).
|
||||||
|
|||||||
Reference in New Issue
Block a user