📦 NEW: sync web support webDataRemoteRegistry (#1697)

This commit is contained in:
fengmk2
2022-01-29 23:39:37 +08:00
committed by GitHub
parent e5c5179e9e
commit 559d5baccf
2 changed files with 13 additions and 2 deletions

View File

@@ -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,
});
};

View File

@@ -15,7 +15,11 @@
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 @@
url: resourceURL + '?sync_upstream=true',
type: 'PUT',
dataType: 'json',
crossDomain: true,
success: handleSyncSucess,
error: function (err) {
var alert = $('<div class="ant-alert ant-alert-error"></div>');
@@ -57,6 +62,7 @@
$.ajax({
url: resourceURL + '/log/' + id,
type: 'GET',
crossDomain: true,
dataType: 'json',
success: function (data) {
if (!data.ok) {
@@ -72,12 +78,13 @@
}
if (syncDone) {
log += '\nSync ' + name + ' complete!';
var logLink = data.logUrl ? (' <a href="' + data.logUrl + '" target="_blank">' + data.logUrl + '</a>') : '';
if (hasFail) {
log += ' But some packages sync failed, you can refresh to sync again.';
location.hash = '';
$notify.html('<div class="ant-alert ant-alert-error">Sync failed.</div>');
$notify.html('<div class="ant-alert ant-alert-error">Sync failed.' + logLink + '</div>');
} else {
$notify.html('<div class="ant-alert ant-alert-success">Sync success.</div>');
$notify.html('<div class="ant-alert ant-alert-success">Sync success.' + logLink + '</div>');
}
clearInterval(timer);
}