Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
This reverts commit b798901.
  • Loading branch information
efstajas committed Jul 30, 2024
1 parent b56795a commit 6477405
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/lib/components/search-bar/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import tokens from '$lib/stores/tokens';
import type { TokenInfoWrapper } from '$lib/stores/tokens/tokens.store';
import { get } from 'svelte/store';
import { isAddress } from 'ethers/lib/utils';
import { isSupportedGitUrl } from '$lib/utils/is-valid-git-url';
import { isValidGitUrl } from '$lib/utils/is-valid-git-url';
import GitProjectService from '$lib/utils/project/GitProjectService';

export enum SearchItemType {
Expand Down Expand Up @@ -74,7 +74,7 @@ export function updateSearchItems(accountId: string | undefined) {
export default function search(input: string | undefined) {
if (!input) return [];

if (isSupportedGitUrl(input)) {
if (isValidGitUrl(input)) {
const { username, repoName } = GitProjectService.deconstructUrl(input);

searchItems.push({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import UnclaimedProjectCard, {
UNCLAIMED_PROJECT_CARD_FRAGMENT,
} from '$lib/components/unclaimed-project-card/unclaimed-project-card.svelte';
import { isSupportedGitUrl } from '$lib/utils/is-valid-git-url';
import { isSupportedGitUrl, isValidGitUrl } from '$lib/utils/is-valid-git-url';
import seededRandomElement from '$lib/utils/seeded-random-element';
import { page } from '$app/stores';
import possibleRandomEmoji from '$lib/utils/project/possible-random-emoji';
Expand Down Expand Up @@ -155,7 +155,7 @@
function submitInput() {
if (isSupportedGitUrl($context.gitUrl)) {
fetchProject();
} else {
} else if (isValidGitUrl($context.gitUrl) && !isSupportedGitUrl($context.gitUrl)) {
validationState = { type: 'invalid', message: 'Unsupported URL' };
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/utils/build-repo-url.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BASE_URL } from './base-url';
import { isSupportedGitUrl } from './is-valid-git-url';
import { isValidGitUrl } from './is-valid-git-url';

export function isDripsProjectUrl(value: string): boolean {
return value.includes(`${BASE_URL}/app/projects/`);
Expand All @@ -24,7 +24,7 @@ export function buildRepositoryURL(url: string): string {
if (forge === 'github') {
const githubUrl = `https://github.com/${repoPath}`;

if (isSupportedGitUrl(githubUrl)) {
if (isValidGitUrl(githubUrl)) {
return `https://github.com/${repoPath}`;
}

Expand Down
10 changes: 4 additions & 6 deletions src/lib/utils/is-valid-git-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@ function validateUrl(url: string, allowedHosts: string[]): boolean {
}
}

export function isSupportedGitUrl(url: string): boolean {
const githubUrlRegex = /^https:\/\/github\.com\/[\w-]+\/[\w.-]+$/;

if (!githubUrlRegex.test(url)) {
return false;
}
export function isValidGitUrl(url: string): boolean {
return validateUrl(url, ['github.com', 'gitlab.com']);
}

export function isSupportedGitUrl(url: string): boolean {
return validateUrl(url, ['github.com']);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { getRepoDriverClient } from '$lib/utils/get-drips-clients';
import { Forge } from 'radicle-drips';
import cached from '$lib/utils/cache/remote/cached';
import queryCacheKey from '$lib/utils/cache/remote/query-cache-key';
import { isSupportedGitUrl } from '$lib/utils/is-valid-git-url';

async function fetchDripsProject(repoUrl: string) {
const getProjectsQuery = gql`
Expand All @@ -33,15 +32,18 @@ async function fetchDripsProject(repoUrl: string) {

const cacheKey = queryCacheKey(getProjectsQuery, [repoUrl], `project-page:${accountId}`);

return await cached(redis, cacheKey, 172800, () =>
query<ProjectByUrlQuery, ProjectByUrlQueryVariables>(
return await cached(
redis,
cacheKey,
172800,
() => query<ProjectByUrlQuery, ProjectByUrlQueryVariables>(
getProjectsQuery,
{
url: repoUrl,
},
fetch,
),
);
)
}

export const load = (async ({ params, fetch, url }) => {
Expand All @@ -66,8 +68,6 @@ export const load = (async ({ params, fetch, url }) => {

const repoUrl = `https://github.com/${githubUsername}/${githubRepoName}`;

if (!isSupportedGitUrl(repoUrl)) throw error(404);

const [repoRes, projectRes] = await Promise.all([
fetch(`/api/github/${encodeURIComponent(repoUrl)}`),
fetchDripsProject(repoUrl),
Expand Down

0 comments on commit 6477405

Please sign in to comment.