Add basic archive restore dialog

This commit is contained in:
Johannes Zellner
2025-02-06 18:22:07 +01:00
parent 0b73633a66
commit 05f31f40eb
5 changed files with 402 additions and 1 deletions
+81
View File
@@ -0,0 +1,81 @@
import { fetcher } from 'pankow';
import DomainsModel from './DomainsModel.js';
function create() {
const accessToken = localStorage.token;
const origin = import.meta.env.VITE_API_ORIGIN || window.location.origin;
const domainsModel = DomainsModel.create();
return {
async list() {
const page = 1;
const per_page = 1000;
let error, result;
try {
result = await fetcher.get(`${origin}/api/v1/archives`, { page, per_page, access_token: accessToken });
} catch (e) {
error = e;
}
if (error || result.status !== 200) return [error || result];
return [null, result.body.archives];
},
async remove(id) {
let error, result;
try {
result = await fetcher.del(`${origin}/api/v1/archives/${id}`, { access_token: accessToken });
} catch (e) {
error = e;
}
if (error || result.status !== 204) return [error || result];
return [null];
},
async restore(id, data) {
// preflight domain checks
if (!data.overwriteDns) {
const allDomains = [{ domain: data.domain, subdomain: data.subdomain }].concat(Object.keys(data.secondaryDomains).map(function (k) {
return {
domain: data.secondaryDomains[k].domain,
subdomain: data.secondaryDomains[k].subdomain
};
}));
for (const domain in allDomains) {
const [error, result] = await domainsModel.checkRecords(domain.domain, domain.subdomain);
if (error) return [error];
const fqdn = domain.subdomain + '.' + domain.domain;
if (result.error) {
if (result.error.reason === 'Access Denied') return [{ type: 'provider', fqdn, message: 'DNS credentials for ' + domain.domain + ' are invalid. Update it in Domains & Certs view' }];
return [{ type: 'provider', fqdn, message: result.error.message }];
}
if (result.needsOverwrite) {
// $scope.archiveRestore.needsOverwrite = true;
// $scope.archiveRestore.overwriteDns = true;
return [{ type: 'externally_exists', fqdn, message: 'DNS Record already exists. Confirm that the domain is not in use for services external to Cloudron' }];
}
}
}
let error, result;
try {
result = await fetcher.post(`${origin}/api/v1/archives/${id}/unarchive`, data, { access_token: accessToken });
} catch (e) {
error = e;
}
if (error || result.status !== 202) return [error || result];
return [null, result.body];
},
};
}
export default {
create,
};