fix(sync): la verification 'depot public' se fait sans jeton, avant tout le reste
Un jeton faux faisait repondre 401 a GitHub avant tout verdict : le refus d'un depot public ne pouvait pas s'exprimer. Public = visible en anonyme. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
+8
-3
@@ -115,7 +115,11 @@ function syncNormalizeRepoUrl(u) {
|
||||
async function syncRepoPublicWarning(cfg) {
|
||||
if (!syncIsGitea(cfg.url)) return '';
|
||||
const repoUrl = cfg.url.split('/contents/')[0];
|
||||
const r = await _webdavCall('get', repoUrl, cfg.user, cfg.pwd);
|
||||
// SANS JETON, expres : "public" veut dire "visible par n'importe qui", et
|
||||
// c'est exactement la question posee. Avec un jeton faux, GitHub repondait
|
||||
// 401 avant de dire quoi que ce soit du depot ; un depot prive repond 404
|
||||
// sans jeton, ce qui veut dire "pas public".
|
||||
const r = await _webdavCall('get', repoUrl, '', '');
|
||||
if (r.status < 200 || r.status >= 300 || !r.payload) return '';
|
||||
try {
|
||||
const o = JSON.parse(new TextDecoder().decode(base64ToBytes(r.payload)));
|
||||
@@ -309,6 +313,9 @@ async function syncTestConnection() {
|
||||
const cfg = await loadSyncConfig(true); // needs the WebDAV credentials
|
||||
if (!cfg || !cfg.url) return toast('Set the WebDAV URL first', 'warning');
|
||||
toast('Testing connection…');
|
||||
// LE DEPOT PUBLIC D'ABORD : il est refuse quel que soit le jeton.
|
||||
const pubFirst = await syncRepoPublicWarning(cfg);
|
||||
if (pubFirst) return toast(pubFirst, 'error');
|
||||
const r = await _webdavCall('test', cfg.url, cfg.user, cfg.pwd);
|
||||
// A reachable Gitea with a valid token is not enough: a URL pointing one
|
||||
// path segment off answers 200 with JSON that is not a file. Checking the
|
||||
@@ -318,8 +325,6 @@ async function syncTestConnection() {
|
||||
try {
|
||||
un = giteaUnwrap(new TextDecoder().decode(base64ToBytes(r.payload || '')));
|
||||
} catch (e) { /* traite comme une forme inattendue */ }
|
||||
const pub = await syncRepoPublicWarning(cfg);
|
||||
if (pub) return toast(pub, 'error');
|
||||
return un
|
||||
? toast('Connection OK · file found in the repository')
|
||||
: toast('Reached Gitea, but this URL does not return a file — ' +
|
||||
|
||||
Reference in New Issue
Block a user