This commit is contained in:
2025-07-17 06:05:35 +09:00
15 changed files with 148 additions and 56 deletions
@@ -6,6 +6,10 @@ class PreviewController < ApplicationController
url = params[:url] url = params[:url]
return head :bad_request unless url.present? return head :bad_request unless url.present?
unless url.start_with?(/http(s)?:\/\//)
url = 'http://' + url
end
html = URI.open(url, open_timeout: 5, read_timeout: 5).read html = URI.open(url, open_timeout: 5, read_timeout: 5).read
doc = Nokogiri::HTML.parse(html) doc = Nokogiri::HTML.parse(html)
title = doc.at('title')&.text&.strip title = doc.at('title')&.text&.strip
@@ -17,11 +21,16 @@ class PreviewController < ApplicationController
def thumbnail def thumbnail
# TODO: 既知ドメインであれば指定のアドレスからサムネールを取得するやぅにする. # TODO: 既知ドメインであれば指定のアドレスからサムネールを取得するやぅにする.
return head :unauthorized unless current_user return head :unauthorized unless current_user
url = params[:url] url = params[:url]
return head :bad_request if url.blank? return head :bad_request if url.blank?
unless url.start_with?(/http(s)?:\/\//)
url = 'http://' + url
end
path = Rails.root.join('tmp', "thumb_#{ SecureRandom.hex }.png") path = Rails.root.join('tmp', "thumb_#{ SecureRandom.hex }.png")
system("node #{ Rails.root }/lib/screenshot.js #{ Shellwords.escape(url) } #{ path }") system("node #{ Rails.root }/lib/screenshot.js #{ Shellwords.escape(url) } #{ path }")
+13 -9
View File
@@ -12,7 +12,7 @@
"@radix-ui/react-dialog": "^1.1.14", "@radix-ui/react-dialog": "^1.1.14",
"@radix-ui/react-switch": "^1.2.5", "@radix-ui/react-switch": "^1.2.5",
"@radix-ui/react-toast": "^1.2.14", "@radix-ui/react-toast": "^1.2.14",
"axios": "^1.9.0", "axios": "^1.10.0",
"camelcase-keys": "^9.1.3", "camelcase-keys": "^9.1.3",
"class-variance-authority": "^0.7.1", "class-variance-authority": "^0.7.1",
"clsx": "^2.1.1", "clsx": "^2.1.1",
@@ -29,7 +29,7 @@
}, },
"devDependencies": { "devDependencies": {
"@eslint/js": "^9.25.0", "@eslint/js": "^9.25.0",
"@types/axios": "^0.9.36", "@types/axios": "^0.14.4",
"@types/markdown-it": "^14.1.2", "@types/markdown-it": "^14.1.2",
"@types/node": "^24.0.13", "@types/node": "^24.0.13",
"@types/react": "^19.1.2", "@types/react": "^19.1.2",
@@ -1897,11 +1897,15 @@
] ]
}, },
"node_modules/@types/axios": { "node_modules/@types/axios": {
"version": "0.9.36", "version": "0.14.4",
"resolved": "https://registry.npmjs.org/@types/axios/-/axios-0.9.36.tgz", "resolved": "https://registry.npmjs.org/@types/axios/-/axios-0.14.4.tgz",
"integrity": "sha512-NLOpedx9o+rxo/X5ChbdiX6mS1atE4WHmEEIcR9NLenRVa5HoVjAvjafwU3FPTqnZEstpoqCaW7fagqSoTDNeg==", "integrity": "sha512-9JgOaunvQdsQ/qW2OPmE5+hCeUB52lQSolecrFrthct55QekhmXEwT203s20RL+UHtCQc15y3VXpby9E7Kkh/g==",
"deprecated": "This is a stub types definition. axios provides its own type definitions, so you do not need this installed.",
"dev": true, "dev": true,
"license": "MIT" "license": "MIT",
"dependencies": {
"axios": "*"
}
}, },
"node_modules/@types/babel__core": { "node_modules/@types/babel__core": {
"version": "7.20.5", "version": "7.20.5",
@@ -2509,9 +2513,9 @@
} }
}, },
"node_modules/axios": { "node_modules/axios": {
"version": "1.9.0", "version": "1.10.0",
"resolved": "https://registry.npmjs.org/axios/-/axios-1.9.0.tgz", "resolved": "https://registry.npmjs.org/axios/-/axios-1.10.0.tgz",
"integrity": "sha512-re4CqKTJaURpzbLHtIi6XpDv20/CnpXOtjRY5/CU32L8gU8ek9UIivcfvSWvmKEngmVbrUtPpdDwWDWL7DNHvg==", "integrity": "sha512-/1xYAC4MP/HEG+3duIhFr4ZQXR4sQXOIe+o6sdqzeykGLx6Upp/1p8MHqhINOvGeP7xyNHe7tsiJByc4SSVUxw==",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"follow-redirects": "^1.15.6", "follow-redirects": "^1.15.6",
+2 -2
View File
@@ -14,7 +14,7 @@
"@radix-ui/react-dialog": "^1.1.14", "@radix-ui/react-dialog": "^1.1.14",
"@radix-ui/react-switch": "^1.2.5", "@radix-ui/react-switch": "^1.2.5",
"@radix-ui/react-toast": "^1.2.14", "@radix-ui/react-toast": "^1.2.14",
"axios": "^1.9.0", "axios": "^1.10.0",
"camelcase-keys": "^9.1.3", "camelcase-keys": "^9.1.3",
"class-variance-authority": "^0.7.1", "class-variance-authority": "^0.7.1",
"clsx": "^2.1.1", "clsx": "^2.1.1",
@@ -31,7 +31,7 @@
}, },
"devDependencies": { "devDependencies": {
"@eslint/js": "^9.25.0", "@eslint/js": "^9.25.0",
"@types/axios": "^0.9.36", "@types/axios": "^0.14.4",
"@types/markdown-it": "^14.1.2", "@types/markdown-it": "^14.1.2",
"@types/node": "^24.0.13", "@types/node": "^24.0.13",
"@types/react": "^19.1.2", "@types/react": "^19.1.2",
+1
View File
@@ -3,6 +3,7 @@
RewriteBase / RewriteBase /
RewriteCond %{REQUEST_URI} !^/api RewriteCond %{REQUEST_URI} !^/api
RewriteCond %{REQUEST_URI} !^/sitemap\.xml
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /index.html [L] RewriteRule ^ /index.html [L]
+1
View File
@@ -0,0 +1 @@
Sitemap: https://hub.nizika.monster/sitemap.xml
+19 -3
View File
@@ -11,6 +11,7 @@ import NotFound from '@/pages/NotFound'
import PostDetailPage from '@/pages/posts/PostDetailPage' import PostDetailPage from '@/pages/posts/PostDetailPage'
import PostListPage from '@/pages/posts/PostListPage' import PostListPage from '@/pages/posts/PostListPage'
import PostNewPage from '@/pages/posts/PostNewPage' import PostNewPage from '@/pages/posts/PostNewPage'
import ServiceUnavailable from '@/pages/ServiceUnavailable'
import SettingPage from '@/pages/users/SettingPage' import SettingPage from '@/pages/users/SettingPage'
import WikiDetailPage from '@/pages/wiki/WikiDetailPage' import WikiDetailPage from '@/pages/wiki/WikiDetailPage'
import WikiDiffPage from '@/pages/wiki/WikiDiffPage' import WikiDiffPage from '@/pages/wiki/WikiDiffPage'
@@ -24,6 +25,7 @@ import type { User } from '@/types'
export default () => { export default () => {
const [user, setUser] = useState<User | null> (null) const [user, setUser] = useState<User | null> (null)
const [status, setStatus] = useState (200)
useEffect (() => { useEffect (() => {
const createUser = async () => { const createUser = async () => {
@@ -40,18 +42,32 @@ export default () => {
if (code) if (code)
{ {
void (async () => { void (async () => {
try
{
const res = await axios.post (`${ API_BASE_URL }/users/verify`, { code }) const res = await axios.post (`${ API_BASE_URL }/users/verify`, { code })
const data = res.data as { valid: boolean, user: any } const data = res.data as { valid: boolean, user: any }
if (data.valid) if (data.valid)
setUser (toCamel (data.user, { deep: true })) setUser (toCamel (data.user, { deep: true }))
else else
await createUser () await createUser ()
}
catch (err)
{
if (axios.isAxiosError (err))
setStatus (err.status ?? 200)
}
}) () }) ()
} }
else else
createUser () createUser ()
}, []) }, [])
switch (status)
{
case 503:
return <ServiceUnavailable />
}
return ( return (
<> <>
<Router> <Router>
@@ -61,13 +77,13 @@ export default () => {
<Routes> <Routes>
<Route path="/" element={<Navigate to="/posts" replace />} /> <Route path="/" element={<Navigate to="/posts" replace />} />
<Route path="/posts" element={<PostListPage />} /> <Route path="/posts" element={<PostListPage />} />
<Route path="/posts/new" element={<PostNewPage />} /> <Route path="/posts/new" element={<PostNewPage user={user} />} />
<Route path="/posts/:id" element={<PostDetailPage user={user} />} /> <Route path="/posts/:id" element={<PostDetailPage user={user} />} />
<Route path="/tags/nico" element={<NicoTagListPage user={user} />} /> <Route path="/tags/nico" element={<NicoTagListPage user={user} />} />
<Route path="/wiki" element={<WikiSearchPage />} /> <Route path="/wiki" element={<WikiSearchPage />} />
<Route path="/wiki/:title" element={<WikiDetailPage />} /> <Route path="/wiki/:title" element={<WikiDetailPage />} />
<Route path="/wiki/new" element={<WikiNewPage />} /> <Route path="/wiki/new" element={<WikiNewPage user={user} />} />
<Route path="/wiki/:id/edit" element={<WikiEditPage />} /> <Route path="/wiki/:id/edit" element={<WikiEditPage user={user} />} />
<Route path="/wiki/:id/diff" element={<WikiDiffPage />} /> <Route path="/wiki/:id/diff" element={<WikiDiffPage />} />
<Route path="/wiki/changes" element={<WikiHistoryPage />} /> <Route path="/wiki/changes" element={<WikiHistoryPage />} />
<Route path="/users/settings" element={<SettingPage user={user} setUser={setUser} />} /> <Route path="/users/settings" element={<SettingPage user={user} setUser={setUser} />} />
+48
View File
@@ -0,0 +1,48 @@
import { Helmet } from 'react-helmet-async'
import errorImg from '@/assets/images/not-found.gif'
import MainArea from '@/components/layout/MainArea'
import { SITE_TITLE } from '@/config'
type Props = { status: number }
export default ({ status }: Props) => {
const [message, rightMsg, leftMsg]: [string, string, string] = (() => {
switch (status)
{
case 403:
return ['権限ないよ(笑)', '帰れ!', '帰れ!']
case 404:
return ['ページないよ(笑)', '帰れ!', '帰れ!']
case 500:
return ['鯖でエラー出たって(嘲笑)', '管理人に', '聯絡を!']
case 503:
return ['鯖死んでるよ(泣)', '管理人に', '聯絡を!']
default:
throw new Error
}
}) ()
const title = message.replaceAll ('', ' (').replaceAll ('', ')')
return (
<MainArea>
<Helmet>
<meta name="robots" content="noindex" />
<title>{title} | {SITE_TITLE}</title>
</Helmet>
<div className="text-6xl font-bold text-transparent whitespace-nowrap
bg-[linear-gradient(90deg,#ff0000,#ff8800,#ffff00,#00ff00,#00ffff,#0000ff,#ff00ff,#ff0000)]
bg-clip-text bg-[length:200%_100%] animate-rainbow-scroll drop-shadow-[0_0_6px_black]
space-y-6 text-center flex flex-col justify-center items-center">
<p>{status}</p>
<div className="flex space-x-4">
<p style={{ writingMode: 'vertical-rl' }}>{leftMsg}</p>
<img src={errorImg} alt="逃げたギター" />
<p style={{ writingMode: 'vertical-rl' }}>{rightMsg}</p>
</div>
<p className="mr-[-.5em]">{message}</p>
</div>
</MainArea>)
}
+4
View File
@@ -0,0 +1,4 @@
import ErrorScreen from '@/components/ErrorScreen'
export default () => <ErrorScreen status={403} />
+2 -24
View File
@@ -1,26 +1,4 @@
import { Helmet } from 'react-helmet-async' import ErrorScreen from '@/components/ErrorScreen'
import notFoundImg from '@/assets/images/not-found.gif'
import MainArea from '@/components/layout/MainArea'
import { SITE_TITLE } from '@/config'
export default () => ( export default () => <ErrorScreen status={404} />
<MainArea>
<Helmet>
<meta name="robots" content="noindex" />
<title> () | {SITE_TITLE}</title>
</Helmet>
<div className="text-6xl font-bold text-transparent whitespace-nowrap
bg-[linear-gradient(90deg,#ff0000,#ff8800,#ffff00,#00ff00,#00ffff,#0000ff,#ff00ff,#ff0000)]
bg-clip-text bg-[length:200%_100%] animate-rainbow-scroll drop-shadow-[0_0_6px_black]
space-y-6 text-center flex flex-col justify-center items-center">
<p>404</p>
<div className="flex space-x-4">
<p style={{ writingMode: 'vertical-rl' }}></p>
<img src={notFoundImg} alt="404" />
<p style={{ writingMode: 'vertical-rl' }}></p>
</div>
<p className="mr-[-.5em]"></p>
</div>
</MainArea>)
@@ -0,0 +1,4 @@
import ErrorScreen from '@/components/ErrorScreen'
export default () => <ErrorScreen status={503} />
+12 -6
View File
@@ -14,6 +14,7 @@ import { toast } from '@/components/ui/use-toast'
import { API_BASE_URL, SITE_TITLE } from '@/config' import { API_BASE_URL, SITE_TITLE } from '@/config'
import { cn } from '@/lib/utils' import { cn } from '@/lib/utils'
import NotFound from '@/pages/NotFound' import NotFound from '@/pages/NotFound'
import ServiceUnavailable from '@/pages/ServiceUnavailable'
import type { Post, User } from '@/types' import type { Post, User } from '@/types'
@@ -25,7 +26,7 @@ export default ({ user }: Props) => {
const [post, setPost] = useState<Post | null> (null) const [post, setPost] = useState<Post | null> (null)
const [editing, setEditing] = useState (true) const [editing, setEditing] = useState (true)
const [found, setFound] = useState (true) const [status, setStatus] = useState (200)
const changeViewedFlg = async () => { const changeViewedFlg = async () => {
const url = `${ API_BASE_URL }/posts/${ id }/viewed` const url = `${ API_BASE_URL }/posts/${ id }/viewed`
@@ -59,8 +60,8 @@ export default ({ user }: Props) => {
} }
catch (err) catch (err)
{ {
if (err.status === 404) if (axios.isAxiosError (err))
setFound (false) setStatus (err.status ?? 200)
} }
}) () }) ()
}, [id]) }, [id])
@@ -74,8 +75,13 @@ export default ({ user }: Props) => {
setEditing (true) setEditing (true)
}, [editing]) }, [editing])
if (!(found)) switch (status)
{
case 404:
return <NotFound /> return <NotFound />
case 503:
return <ServiceUnavailable />
}
const url = post ? new URL (post.url) : null const url = post ? new URL (post.url) : null
const nicoFlg = url?.hostname.split ('.').slice (-2).join ('.') === 'nicovideo.jp' const nicoFlg = url?.hostname.split ('.').slice (-2).join ('.') === 'nicovideo.jp'
@@ -88,8 +94,8 @@ export default ({ user }: Props) => {
return ( return (
<> <>
<Helmet> <Helmet>
{(post?.thumbnail || post?.thumbnailBase) && {(post?.thumbnail || post?.thumbnailBase) && (
<meta name="thumbnail" content={post.thumbnail || post.thumbnailBase} />} <meta name="thumbnail" content={post.thumbnail || post.thumbnailBase} />)}
{post && <title>{`${ post.title || post.url } | ${ SITE_TITLE }`}</title>} {post && <title>{`${ post.title || post.url } | ${ SITE_TITLE }`}</title>}
</Helmet> </Helmet>
<TagDetailSidebar post={post} /> <TagDetailSidebar post={post} />
+1 -1
View File
@@ -82,7 +82,7 @@ export default () => {
<title> <title>
{tags.length {tags.length
? `${ tags.join (anyFlg ? ' or ' : ' and ') } | ${ SITE_TITLE }` ? `${ tags.join (anyFlg ? ' or ' : ' and ') } | ${ SITE_TITLE }`
: `${ SITE_TITLE } 〜 ぼざクリ関聯綜合リンク集サイト`} : `${ SITE_TITLE } 〜 ぼざクリーチャーシリーズ綜合リンク集サイト`}
</title> </title>
</Helmet> </Helmet>
<TagSidebar posts={posts.slice (0, 20)} /> <TagSidebar posts={posts.slice (0, 20)} />
+10 -1
View File
@@ -11,8 +11,17 @@ import MainArea from '@/components/layout/MainArea'
import { Button } from '@/components/ui/button' import { Button } from '@/components/ui/button'
import { toast } from '@/components/ui/use-toast' import { toast } from '@/components/ui/use-toast'
import { API_BASE_URL, SITE_TITLE } from '@/config' import { API_BASE_URL, SITE_TITLE } from '@/config'
import Forbidden from '@/pages/Forbidden'
import type { User } from '@/types'
type Props = { user: User | null }
export default ({ user }: Props) => {
if (!(['admin', 'member'].some (r => user?.role === r)))
return <Forbidden />
export default () => {
const navigate = useNavigate () const navigate = useNavigate ()
const [title, setTitle] = useState ('') const [title, setTitle] = useState ('')
+8 -2
View File
@@ -8,15 +8,21 @@ import { useParams, useNavigate } from 'react-router-dom'
import MainArea from '@/components/layout/MainArea' import MainArea from '@/components/layout/MainArea'
import { toast } from '@/components/ui/use-toast' import { toast } from '@/components/ui/use-toast'
import { API_BASE_URL, SITE_TITLE } from '@/config' import { API_BASE_URL, SITE_TITLE } from '@/config'
import Forbidden from '@/pages/Forbidden'
import 'react-markdown-editor-lite/lib/index.css' import 'react-markdown-editor-lite/lib/index.css'
import type { WikiPage } from '@/types' import type { User, WikiPage } from '@/types'
const mdParser = new MarkdownIt const mdParser = new MarkdownIt
type Props = { user: User | null }
export default ({ user }: Props) => {
if (!(['admin', 'member'].some (r => user?.role === r)))
return <Forbidden />
export default () => {
const { id } = useParams () const { id } = useParams ()
const navigate = useNavigate () const navigate = useNavigate ()
+8 -2
View File
@@ -8,15 +8,21 @@ import { useLocation, useNavigate } from 'react-router-dom'
import MainArea from '@/components/layout/MainArea' import MainArea from '@/components/layout/MainArea'
import { toast } from '@/components/ui/use-toast' import { toast } from '@/components/ui/use-toast'
import { API_BASE_URL, SITE_TITLE } from '@/config' import { API_BASE_URL, SITE_TITLE } from '@/config'
import Forbidden from '@/pages/Forbidden'
import 'react-markdown-editor-lite/lib/index.css' import 'react-markdown-editor-lite/lib/index.css'
import type { WikiPage } from '@/types' import type { User, WikiPage } from '@/types'
const mdParser = new MarkdownIt const mdParser = new MarkdownIt
type Props = { user: User | null }
export default ({ user }: Props) => {
if (!(['admin', 'member'].some (r => user?.role === r)))
return <Forbidden />
export default () => {
const location = useLocation () const location = useLocation ()
const navigate = useNavigate () const navigate = useNavigate ()