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:
@@ -8221,8 +8221,17 @@ async function init() {
|
||||
if (syncCfgBox) syncCfgBox.style.display = on ? '' : 'none';
|
||||
toast(on ? 'Sync enabled' : 'Sync disabled');
|
||||
});
|
||||
if (syncUrlEl) syncUrlEl.addEventListener('change', e =>
|
||||
Bridge.setPref(SYNC_PREFS.url, e.target.value.trim()));
|
||||
// L'adresse du depot suffit (github.com/O/R.git, Gitea) : elle est
|
||||
// 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 =>
|
||||
Bridge.setPref(SYNC_PREFS.user, e.target.value.trim()));
|
||||
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/');
|
||||
}
|
||||
|
||||
// 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
|
||||
// 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).
|
||||
|
||||
Reference in New Issue
Block a user