Skip to content

Commit

Permalink
Actually fix URL paths case sensitivity
Browse files Browse the repository at this point in the history
  • Loading branch information
kasbah committed Jan 19, 2025
1 parent c92b223 commit cb9660e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.tsbuildinfo
# IDEs
.idea/

Expand Down
24 changes: 11 additions & 13 deletions frontend/src/pages/[user]/[repo]/[project]/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import { bool } from 'prop-types'
import getConfig from 'next/config'

import { getRepo, repoExists } from '@utils/giteaApi'
import { getRepo } from '@utils/giteaApi'
import {
getBoardBomInfo,
getBoardGerberInfo,
Expand All @@ -20,27 +20,25 @@ const MultiProjectPage = props =>
props.notFound ? <Custom404 /> : <SharedProjectPage {...props} />

MultiProjectPage.getInitialProps = async ({ query, res = null }) => {
const username = query.user.toLowerCase()
const repoName = query.repo.toLowerCase()
const projectName = query.project.toLowerCase()
const userLowerCase = query.user.toLowerCase()
const repoLowerCase = query.repo.toLowerCase()
const projectName = query.project

const repoFullName = `${username}/${repoName}`

const rootAssetPath = `${assetUrl}/${repoFullName}/HEAD`
const assetPath = `${rootAssetPath}/${projectName}`

const exists = await repoExists(repoFullName)
if (exists) {
const repo = await getRepo(`${userLowerCase}/${repoLowerCase}`)
if (repo) {
const repoName = repo.name
const username = repo.owner.login
const repoFullName = `${username}/${repoName}`
const rootAssetPath = `${assetUrl}/${repoFullName}/HEAD`
const assetPath = `${rootAssetPath}/${projectName}`
const [
repo,
readme,
[bomInfoExists, bomInfo],
[gerberInfoExists, gerberInfo],
[kitspaceYAMLExists, kitspaceYamlArray],
finishedProcessing,
hasIBOM,
] = await Promise.all([
getRepo(repoFullName),
getReadme(assetPath),
getBoardBomInfo(assetPath),
getBoardGerberInfo(assetPath),
Expand Down
13 changes: 8 additions & 5 deletions frontend/src/pages/[user]/[repo]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import getConfig from 'next/config'
import useSWR, { SWRConfig, unstable_serialize } from 'swr'

import { getKitspaceYamlArray } from '@utils/projectPage'
import { getRepo, repoExists } from '@utils/giteaApi'
import { getRepo } from '@utils/giteaApi'
import { waitFor } from '@utils/index'
import Project from '@models/Project'
import { searchFetcher, SearchFetcherParams } from '@hooks/useLazySearch'
Expand Down Expand Up @@ -41,18 +41,21 @@ const RepoPage = (props: RepoPageProps) => {
RepoPage.getInitialProps = async (ctx: NextPageContext): Promise<RepoPageProps> => {
const { query, res } = ctx

const username = (query.user as string).toLowerCase()
const repoName = (query.repo as string).toLowerCase()
const userLowerCase = (query.user as string).toLowerCase()
const repoLowerCase = (query.repo as string).toLowerCase()

const exists = await repoExists(`${username}/${repoName}`)
const repo = await getRepo(`${userLowerCase}/${repoLowerCase}`)

if (!exists) {
if (!repo) {
if (res != null) {
res.statusCode = 404
}
return { errorCode: 404 }
}

const repoName = repo.name
const username = repo.owner.login

const kitspaceYamlArray = await getYamlArray(username, repoName)

if (!kitspaceYamlArray) {
Expand Down
10 changes: 6 additions & 4 deletions frontend/src/pages/[user]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
searchFetcher,
useLazySearch,
} from '@hooks/useLazySearch'
import { userExists } from '@utils/giteaApi'
import { getUser } from '@utils/giteaApi'
import Project from '@models/Project'

interface UserPageProps {
Expand All @@ -19,14 +19,16 @@ interface UserPageProps {
}

export const getServerSideProps: GetServerSideProps = async ({ params }) => {
const username = (params.user as string).toLowerCase()
const exists = await userExists(username)
if (!exists) {
const userLowerCase = (params.user as string).toLowerCase()
const user = await getUser(userLowerCase)
if (!user) {
return {
notFound: true,
}
}

const username = user.login

const searchParams = {
query: '',
filter: `ownerName = ${username}`,
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/utils/giteaApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ export const repoExists = async fullname => {
/**
* Check if a user exist
* @param username{string}
* @returns {Promise<boolean>}
* @returns {Promise<Object|null>}
*/
export const userExists = async username => {
export const getUser = async username => {
const endpoint = `${giteaApiUrl}/users/${username}`

const res = await fetch(endpoint, {
Expand All @@ -46,5 +46,5 @@ export const userExists = async username => {
headers,
})

return res.ok
return res.ok ? res.json() : null
}

0 comments on commit cb9660e

Please sign in to comment.