From 559d5baccfc3f5fa582461856f7048927aac3f23 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Sat, 29 Jan 2022 23:39:37 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=A6=20NEW:=20sync=20web=20support=20we?= =?UTF-8?q?bDataRemoteRegistry=20(#1697)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/web/show_sync.js | 4 ++++ view/web/sync.html | 11 +++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/controllers/web/show_sync.js b/controllers/web/show_sync.js index a5f1d8080..2cfaade1d 100644 --- a/controllers/web/show_sync.js +++ b/controllers/web/show_sync.js @@ -1,5 +1,7 @@ 'use strict'; +var config = require('../../config'); + module.exports = function* showSync() { var name = this.params.name || this.params[0] || this.query.name; if (!name) { @@ -11,9 +13,11 @@ module.exports = function* showSync() { name = splits[1]; type = splits[0]; } + var syncTaskUrl = config.enableWebDataRemoteRegistry ? `${config.webDataRemoteRegistry}/${name}/sync` : null; yield this.render('sync', { type: type, name: name, title: 'Sync ' + type + ' - ' + name, + syncTaskUrl, }); }; diff --git a/view/web/sync.html b/view/web/sync.html index 436e72c26..a34025cf1 100644 --- a/view/web/sync.html +++ b/view/web/sync.html @@ -15,7 +15,11 @@

Log

if (type !== 'package') { name = type + ':' + name; } + <% if (syncTaskUrl) { %> + var resourceURL = '<%= syncTaskUrl %>'; + <% } else { %> var resourceURL = '/sync/' + name; + <% } %> $(function() { var checkLogId = location.hash.match(/logid=(\d+)/); var logid = checkLogId ? checkLogId[1] : ''; @@ -26,6 +30,7 @@

Log

url: resourceURL + '?sync_upstream=true', type: 'PUT', dataType: 'json', + crossDomain: true, success: handleSyncSucess, error: function (err) { var alert = $('
'); @@ -57,6 +62,7 @@

Log

$.ajax({ url: resourceURL + '/log/' + id, type: 'GET', + crossDomain: true, dataType: 'json', success: function (data) { if (!data.ok) { @@ -72,12 +78,13 @@

Log

} if (syncDone) { log += '\nSync ' + name + ' complete!'; + var logLink = data.logUrl ? (' ' + data.logUrl + '') : ''; if (hasFail) { log += ' But some packages sync failed, you can refresh to sync again.'; location.hash = ''; - $notify.html('
Sync failed.
'); + $notify.html('
Sync failed.' + logLink + '
'); } else { - $notify.html('
Sync success.
'); + $notify.html('
Sync success.' + logLink + '
'); } clearInterval(timer); }