Changeset View
Changeset View
Standalone View
Standalone View
assets/src/bundles/save/index.js
/** | /** | ||||
* Copyright (C) 2018-2022 The Software Heritage developers | * Copyright (C) 2018-2022 The Software Heritage developers | ||||
* See the AUTHORS file at the top-level directory of this distribution | * See the AUTHORS file at the top-level directory of this distribution | ||||
* License: GNU Affero General Public License version 3, or any later version | * License: GNU Affero General Public License version 3, or any later version | ||||
* See top-level LICENSE file for more information | * See top-level LICENSE file for more information | ||||
*/ | */ | ||||
import {csrfPost, handleFetchError, isGitRepoUrl, htmlAlert, | |||||
getCanonicalOriginURL, getHumanReadableDate} from 'utils/functions'; | |||||
import {swhSpinnerSrc} from 'utils/constants'; | import {swhSpinnerSrc} from 'utils/constants'; | ||||
import artifactFormRowTemplate from './artifact-form-row.ejs'; | import { | ||||
csrfPost, getCanonicalOriginURL, getHumanReadableDate, handleFetchError, | |||||
htmlAlert, isGitRepoUrl, validateUrl | |||||
} from 'utils/functions'; | |||||
import userRequestsFilterCheckboxFn from 'utils/requests-filter-checkbox.ejs'; | import userRequestsFilterCheckboxFn from 'utils/requests-filter-checkbox.ejs'; | ||||
import artifactFormRowTemplate from './artifact-form-row.ejs'; | |||||
let saveRequestsTable; | let saveRequestsTable; | ||||
async function originSaveRequest( | async function originSaveRequest( | ||||
originType, originUrl, extraData, | originType, originUrl, extraData, | ||||
acceptedCallback, pendingCallback, errorCallback | acceptedCallback, pendingCallback, errorCallback | ||||
) { | ) { | ||||
// Actually trigger the origin save request | // Actually trigger the origin save request | ||||
▲ Show 20 Lines • Show All 326 Lines • ▼ Show 20 Lines | $(document).ready(() => { | ||||
}); | }); | ||||
}); | }); | ||||
} | } | ||||
export function validateSaveOriginUrl(input) { | export function validateSaveOriginUrl(input) { | ||||
const originType = $('#swh-input-visit-type').val(); | const originType = $('#swh-input-visit-type').val(); | ||||
let originUrl = null; | const allowedProtocols = ['http:', 'https:', 'svn:', 'git:', 'rsync:', | ||||
let validUrl = true; | 'pserver:', 'ssh:', 'bzr:']; | ||||
const originUrl = validateUrl(input.value.trim(), allowedProtocols); | |||||
try { | |||||
originUrl = new URL(input.value.trim()); | |||||
} catch (TypeError) { | |||||
validUrl = false; | |||||
} | |||||
if (validUrl) { | let validUrl = originUrl !== null; | ||||
const allowedProtocols = ['http:', 'https:', 'svn:', 'git:', 'rsync:', 'pserver:', 'ssh:', 'bzr:']; | |||||
validUrl = ( | |||||
allowedProtocols.find(protocol => protocol === originUrl.protocol) !== undefined | |||||
); | |||||
} | |||||
if (validUrl && originType === 'git') { | if (validUrl && originType === 'git') { | ||||
validUrl = isGitRepoUrl(originUrl); | validUrl = isGitRepoUrl(originUrl); | ||||
} | } | ||||
let customValidity = ''; | let customValidity = ''; | ||||
if (validUrl) { | if (validUrl) { | ||||
if ((originUrl.password !== '' && originUrl.password !== 'anonymous')) { | if ((originUrl.password !== '' && originUrl.password !== 'anonymous')) { | ||||
▲ Show 20 Lines • Show All 177 Lines • Show Last 20 Lines |