Changeset View
Changeset View
Standalone View
Standalone View
assets/src/bundles/vault/vault-create-tasks.js
Show All 13 Lines | const alertStyle = { | ||||
'z-index': '100000' | 'z-index': '100000' | ||||
}; | }; | ||||
export async function vaultRequest(objectType, swhid) { | export async function vaultRequest(objectType, swhid) { | ||||
let vaultUrl; | let vaultUrl; | ||||
if (objectType === 'directory') { | if (objectType === 'directory') { | ||||
vaultUrl = Urls.api_1_vault_cook_flat(swhid); | vaultUrl = Urls.api_1_vault_cook_flat(swhid); | ||||
} else { | } else { | ||||
vaultUrl = Urls.api_1_vault_cook_gitfast(swhid); | vaultUrl = Urls.api_1_vault_cook_git_bare(swhid); | ||||
} | } | ||||
// check if object has already been cooked | // check if object has already been cooked | ||||
const response = await fetch(vaultUrl); | const response = await fetch(vaultUrl); | ||||
const data = await response.json(); | const data = await response.json(); | ||||
// object needs to be cooked | // object needs to be cooked | ||||
if (data.exception === 'NotFoundExc' || data.status === 'failed') { | if (data.exception === 'NotFoundExc' || data.status === 'failed') { | ||||
// if last cooking has failed, remove previous task info from localStorage | // if last cooking has failed, remove previous task info from localStorage | ||||
Show All 32 Lines | async function addVaultCookingTask(objectType, cookingTask) { | ||||
if (vaultCookingTasks.find(val => { | if (vaultCookingTasks.find(val => { | ||||
return val.bundle_type === cookingTask.bundle_type && | return val.bundle_type === cookingTask.bundle_type && | ||||
val.swhid === cookingTask.swhid; | val.swhid === cookingTask.swhid; | ||||
}) === undefined) { | }) === undefined) { | ||||
let cookingUrl; | let cookingUrl; | ||||
if (cookingTask.bundle_type === 'flat') { | if (cookingTask.bundle_type === 'flat') { | ||||
cookingUrl = Urls.api_1_vault_cook_flat(cookingTask.swhid); | cookingUrl = Urls.api_1_vault_cook_flat(cookingTask.swhid); | ||||
} else { | } else { | ||||
cookingUrl = Urls.api_1_vault_cook_gitfast(cookingTask.swhid); | cookingUrl = Urls.api_1_vault_cook_git_bare(cookingTask.swhid); | ||||
} | } | ||||
if (cookingTask.email) { | if (cookingTask.email) { | ||||
cookingUrl += '?email=' + cookingTask.email; | cookingUrl += '?email=' + cookingTask.email; | ||||
} | } | ||||
try { | try { | ||||
const response = await csrfPost(cookingUrl); | const response = await csrfPost(cookingUrl); | ||||
handleFetchError(response); | handleFetchError(response); | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | export async function fetchDirectoryArchive(directorySwhid) { | ||||
const data = await response.json(); | const data = await response.json(); | ||||
swh.vault.fetchCookedObject(data.fetch_url); | swh.vault.fetchCookedObject(data.fetch_url); | ||||
} | } | ||||
export function cookRevisionArchive(revisionId) { | export function cookRevisionArchive(revisionId) { | ||||
const email = $('#swh-vault-revision-email').val().trim(); | const email = $('#swh-vault-revision-email').val().trim(); | ||||
if (!email || validateEmail(email)) { | if (!email || validateEmail(email)) { | ||||
const cookingTask = { | const cookingTask = { | ||||
'bundle_type': 'gitfast', | 'bundle_type': 'git_bare', | ||||
'swhid': revisionId, | 'swhid': revisionId, | ||||
'email': email, | 'email': email, | ||||
'status': 'new' | 'status': 'new' | ||||
}; | }; | ||||
addVaultCookingTask('revision', cookingTask); | addVaultCookingTask('revision', cookingTask); | ||||
} else { | } else { | ||||
$('#invalid-email-modal').modal('show'); | $('#invalid-email-modal').modal('show'); | ||||
} | } | ||||
} | } | ||||
export async function fetchRevisionArchive(revisionSwhid) { | export async function fetchRevisionArchive(revisionSwhid) { | ||||
$('#vault-fetch-directory-modal').modal('hide'); | $('#vault-fetch-directory-modal').modal('hide'); | ||||
const vaultUrl = Urls.api_1_vault_cook_gitfast(revisionSwhid); | const vaultUrl = Urls.api_1_vault_cook_git_bare(revisionSwhid); | ||||
const response = await fetch(vaultUrl); | const response = await fetch(vaultUrl); | ||||
const data = await response.json(); | const data = await response.json(); | ||||
swh.vault.fetchCookedObject(data.fetch_url); | swh.vault.fetchCookedObject(data.fetch_url); | ||||
} | } |