精简后的项目:仅保留 api/ui 源码、文档、构建依赖

This commit is contained in:
gallery
2026-09-11 16:11:09 +08:00
commit 490e85634e
457 changed files with 86862 additions and 0 deletions
+14
View File
@@ -0,0 +1,14 @@
import { render, screen } from '@testing-library/react'
import React from 'react'
import Layout from './Layout'
test('Layout component', () => {
render(
<Layout title="Test title">
<p>layout_content</p>
</Layout>
)
expect(screen.getByTestId('Layout')).toBeInTheDocument()
expect(screen.getByText('layout_content')).toBeInTheDocument()
})
+53
View File
@@ -0,0 +1,53 @@
import { gql } from '@apollo/client'
import React, { useContext } from 'react'
import { Helmet } from 'react-helmet'
import Header from '../header/Header'
import { Authorized } from '../routes/AuthorizedRoute'
import { Sidebar, SidebarContext } from '../sidebar/Sidebar'
import MainMenu from './MainMenu'
export const ADMIN_QUERY = gql`
query adminQuery {
myUser {
admin
}
}
`
type LayoutProps = {
children: React.ReactNode
title: string
}
const Layout = ({ children, title, ...otherProps }: LayoutProps) => {
const { pinned, content: sidebarContent } = useContext(SidebarContext)
return (
<>
<Helmet>
<title>
{title ? `${title} - Gallery.FuKun.Net` : `Gallery.FuKun.Net`}
</title>
</Helmet>
<div className="relative" {...otherProps} data-testid="Layout">
<Header />
<div className="">
<Authorized>
<MainMenu />
</Authorized>
<div
className={`mx-6 my-3 lg:mt-5 lg:mr-16 lg:ml-[292px] ${
pinned && sidebarContent ? 'lg:pr-[420px]' : ''
}`}
id="layout-content"
>
{children}
</div>
</div>
<Sidebar />
</div>
</>
)
}
export default Layout
@@ -0,0 +1,59 @@
import React from 'react'
import { MockedProvider } from '@apollo/client/testing'
import { render, screen } from '@testing-library/react'
import * as authentication from '../../helpers/authentication'
import { ADMIN_QUERY } from './Layout'
import { MemoryRouter } from 'react-router-dom'
import MainMenu, { MAPBOX_QUERY } from './MainMenu'
vi.mock('../../helpers/authentication.ts')
const authTokenMock = vi.mocked(authentication.authToken)
afterEach(() => {
authTokenMock.mockClear()
})
test('Layout sidebar component', async () => {
authTokenMock.mockImplementation(() => 'test-token')
const mockedGraphql = [
{
request: {
query: ADMIN_QUERY,
},
result: {
data: {
myUser: {
admin: true,
},
},
},
},
{
request: {
query: MAPBOX_QUERY,
},
result: {
data: {
mapboxToken: true,
},
},
},
]
render(
<MockedProvider mocks={mockedGraphql} addTypename={false}>
<MemoryRouter>
<MainMenu />
</MemoryRouter>
</MockedProvider>
)
expect(screen.getByText('Timeline')).toBeInTheDocument()
expect(screen.getByText('Albums')).toBeInTheDocument()
expect(await screen.findByText('Settings')).toBeInTheDocument()
expect(await screen.findByText('Places')).toBeInTheDocument()
})
+159
View File
@@ -0,0 +1,159 @@
import React from 'react'
import { NavLink } from 'react-router-dom'
import { useQuery, gql } from '@apollo/client'
import { authToken } from '../../helpers/authentication'
import { useTranslation } from 'react-i18next'
import { mapboxEnabledQuery } from '../../__generated__/mapboxEnabledQuery'
import { tailwindClassNames } from '../../helpers/utils'
import { faceDetectionEnabled } from './__generated__/faceDetectionEnabled'
export const MAPBOX_QUERY = gql`
query mapboxEnabledQuery {
mapboxToken
}
`
export const FACE_DETECTION_ENABLED_QUERY = gql`
query faceDetectionEnabled {
siteInfo {
faceDetectionEnabled
}
}
`
type MenuButtonProps = {
to: string
exact: boolean
label: string
background: string
activeClasses?: string
className?: string
icon?: React.ReactNode
}
const MenuButton = ({
to,
exact,
label,
background,
icon,
activeClasses,
className,
}: MenuButtonProps) => {
return (
<NavLink
to={to}
end={exact}
className={({ isActive }) =>
tailwindClassNames(
`rounded-lg my-2 outline-none`,
className,
{
activeClasses: isActive,
}
)
}
>
<li className="flex items-center">
<div
className={`w-12 h-12 p-1.5 lg:w-8 lg:h-8 lg:p-1 w-full h-full rounded-lg`}
style={{ backgroundColor: background }}
>
{icon}
</div>
<span className="hidden lg:block ml-2">{label}</span>
</li>
</NavLink>
)
}
const MenuSeparator = () => (
<hr className="hidden lg:block my-3 border-gray-200 dark:border-dark-border" />
)
export const MainMenu = () => {
const { t } = useTranslation()
const mapboxQuery = authToken()
? useQuery<mapboxEnabledQuery>(MAPBOX_QUERY)
: null
const faceDetectionEnabledQuery = authToken()
? useQuery<faceDetectionEnabled>(FACE_DETECTION_ENABLED_QUERY)
: null
const mapboxEnabled = !!mapboxQuery?.data?.mapboxToken
const faceDetectionEnabled =
!!faceDetectionEnabledQuery?.data?.siteInfo?.faceDetectionEnabled
return (
<div className="fixed w-full bottom-0 lg:bottom-auto lg:top-16 z-30 bg-dark-bg lg:w-[240px] lg:ml-0 lg:mr-5 flex-shrink-0">
<ul className="flex justify-around py-2 px-2 max-w-lg mx-auto lg:flex-col lg:p-0">
<MenuButton
to="/timeline"
exact
label={t('sidemenu.photos', 'Timeline')}
background="#000000"
activeClasses="bg-[#1a1a1a] dark:bg-[#1a1a1a]"
className="focus:ring-0 shadow-none"
icon={
<svg
viewBox="0 0 24 24"
fill="none"
stroke="white"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
>
<rect x="3" y="3" width="18" height="18" rx="2" />
<circle cx="8.5" cy="8.5" r="1.5" />
<path d="m21 15-5-5L5 21" />
</svg>
}
/>
<MenuButton
to="/albums"
exact
label={t('sidemenu.albums', 'Albums')}
background="#000000"
activeClasses="bg-[#1a1a1a] dark:bg-[#1a1a1a]"
className="focus:ring-0 shadow-none"
icon={
<svg
viewBox="0 0 24 24"
fill="none"
stroke="white"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
>
<path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z" />
</svg>
}
/>
<MenuButton
to="/settings"
exact
label={t('sidemenu.settings', 'Settings')}
background="#000000"
activeClasses="bg-[#1a1a1a] dark:bg-[#1a1a1a]"
className="focus:ring-0 shadow-none"
icon={
<svg
viewBox="0 0 24 24"
fill="none"
stroke="white"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
>
<circle cx="12" cy="12" r="3" />
<path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z" />
</svg>
}
/>
</ul>
</div>
)
}
export default MainMenu
+23
View File
@@ -0,0 +1,23 @@
/* tslint:disable */
/* eslint-disable */
// @generated
// This file was automatically generated and should not be edited.
// ====================================================
// GraphQL query operation: adminQuery
// ====================================================
export interface adminQuery_myUser {
__typename: "User";
/**
* Whether or not the user has admin privileges
*/
admin: boolean;
}
export interface adminQuery {
/**
* Information about the currently logged in user
*/
myUser: adminQuery_myUser;
}
@@ -0,0 +1,20 @@
/* tslint:disable */
/* eslint-disable */
// @generated
// This file was automatically generated and should not be edited.
// ====================================================
// GraphQL query operation: faceDetectionEnabled
// ====================================================
export interface faceDetectionEnabled_siteInfo {
__typename: "SiteInfo";
/**
* Whether or not face detection is enabled and working
*/
faceDetectionEnabled: boolean;
}
export interface faceDetectionEnabled {
siteInfo: faceDetectionEnabled_siteInfo;
}
@@ -0,0 +1,15 @@
/* tslint:disable */
/* eslint-disable */
// @generated
// This file was automatically generated and should not be edited.
// ====================================================
// GraphQL query operation: mapboxEnabledQuery
// ====================================================
export interface mapboxEnabledQuery {
/**
* Get the mapbox api token, returns null if mapbox is not enabled
*/
mapboxToken: string | null;
}
@@ -0,0 +1,5 @@
<svg viewBox="0 0 24 24" fill="white">
<path
d="M6,16 L19,16 C19.5522847,16 20,16.4477153 20,17 L20,21 C20,21.5522847 19.5522847,22 19,22 L6,22 C4.8954305,22 4,21.1045695 4,20 L4,18 C4,16.8954305 4.8954305,16 6,16 Z" fillOpacity="0.75" />
<path d="M19,2 C19.5522847,2 20,2.44771525 20,3 L20,19 C20,19.5522847 19.5522847,20 19,20 L6,20 C4.8954305,20 4,19.1045695 4,18 L4,4 C4,2.8954305 4.8954305,2 6,2 L19,2 Z M14.4676845,9 L11.5079767,12.9536523 L9.50029382,10.8745763 L7,14 L18,14 L14.4676845,9 Z M10.75,9 C10.3357864,9 10,9.33578644 10,9.75 C10,10.1642136 10.3357864,10.5 10.75,10.5 C11.1642136,10.5 11.5,10.1642136 11.5,9.75 C11.5,9.33578644 11.1642136,9 10.75,9 Z" />
</svg>

After

Width:  |  Height:  |  Size: 686 B

@@ -0,0 +1,7 @@
<svg viewBox="0 0 24 24" fill="white">
<path
d="M12,15 C15.1826579,15 18.0180525,16.4868108 19.8494955,18.8037439 L20,19 C20,20.6568542 18.6568542,22 17,22 L7,22 C5.34314575,22 4,20.6568542 4,19 L4.15050454,18.8037439 C5.9819475,16.4868108 8.81734212,15 12,15 Z"
fillOpacity="0.75"
></path>
<circle cx="12" cy="11" r="6"></circle>
</svg>

After

Width:  |  Height:  |  Size: 351 B

@@ -0,0 +1,4 @@
<svg viewBox="0 0 24 24" fill="white">
<path d="M15.6971052,10 L23.9367603,21.526562 C23.6878671,22.9323278 22.4600272,24 20.982819,24 L5.851819,24 L15.6971052,10 Z" />
<path d="M5.59307375,14 L15.562,24 L2.982819,24 C1.43507633,24 0.161084327,22.8279341 -3.56225466e-14,21.3229592 L5.59307375,14 Z" fillOpacity="0.75"/>
</svg>

After

Width:  |  Height:  |  Size: 331 B

@@ -0,0 +1,8 @@
<svg viewBox="0 0 24 24" fill="white">
<path d="M3.4,3.34740684 C3.47896999,3.34740684 3.55617307,3.37078205 3.62188008,3.41458672 L9,7 L9,21 L3.4452998,17.2968665 C3.16710114,17.1114008 3,16.7991694 3,16.4648162 L3,3.74740684 C3,3.52649294 3.1790861,3.34740684 3.4,3.34740684 Z M15,3 L21.4961389,6.71207939 C21.8077139,6.89012225 22,7.22146569 22,7.58032254 L22,20.3107281 C22,20.531642 21.8209139,20.7107281 21.6,20.7107281 C21.5303892,20.7107281 21.4619835,20.692562 21.4015444,20.6580254 L15,17 L15,3 Z" />
<polygon
fillOpacity="0.75"
transform="translate(12, 12) scale(1, -1) translate(-12, -12)"
points="9 3 15 7 15 21 9 17"
/>
</svg>

After

Width:  |  Height:  |  Size: 658 B

@@ -0,0 +1,7 @@
<svg viewBox="0 0 24 24" fill="white">
<path
d="M13.4691754,16.7806702 L13,21 L11,21 L10.5318353,16.7809803 C10.9960818,16.9233714 11.4890921,17 12,17 C12.5112786,17 13.0046337,16.9232601 13.4691754,16.7806702 Z M16.4192861,14.3409153 L19.0710678,17.6568542 L17.6568542,19.0710678 L14.3409153,16.4192861 C15.2243208,15.9503691 15.9503691,15.2243208 16.4192861,14.3409153 Z M9.65908474,16.4192861 L6.34314575,19.0710678 L4.92893219,17.6568542 L7.5807139,14.3409153 C8.04963086,15.2243208 8.77567918,15.9503691 9.65908474,16.4192861 Z M7,12 C7,12.5112786 7.07673988,13.0046337 7.21932976,13.4691754 L3,13 L3,11 L7.21901966,10.5318353 C7.07662862,10.9960818 7,11.4890921 7,12 Z M16.7809803,10.5318353 L21,11 L21,13 L16.7806702,13.4691754 C16.9232601,13.0046337 17,12.5112786 17,12 C17,11.4890921 16.9233714,10.9960818 16.7809803,10.5318353 Z M6.34314575,4.92893219 L9.65908474,7.5807139 C8.77567918,8.04963086 8.04963086,8.77567918 7.5807139,9.65908474 L4.92893219,6.34314575 L6.34314575,4.92893219 Z M17.6568542,4.92893219 L19.0710678,6.34314575 L16.4192861,9.65908474 C15.9503691,8.77567918 15.2243208,8.04963086 14.3409153,7.5807139 L17.6568542,4.92893219 Z M13,3 L13.4691754,7.21932976 C13.0046337,7.07673988 12.5112786,7 12,7 C11.4890921,7 10.9960818,7.07662862 10.5318353,7.21901966 L11,3 L13,3 Z"
fillOpacity="0.76"
/>
<path d="M12,5 C15.8659932,5 19,8.13400675 19,12 C19,15.8659932 15.8659932,19 12,19 C8.13400675,19 5,15.8659932 5,12 C5,8.13400675 8.13400675,5 12,5 Z M12,8 C9.790861,8 8,9.790861 8,12 C8,14.209139 9.790861,16 12,16 C14.209139,16 16,14.209139 16,12 C16,9.790861 14.209139,8 12,8 Z" />
</svg>

After

Width:  |  Height:  |  Size: 1.6 KiB