Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
yunochi committed Nov 24, 2024
2 parents fbdc0ff + 8770586 commit 5b442a3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/app/api/db/create-question/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export async function POST(req: NextRequest) {
if (!tokenPayload) {
throw new Error(`No Auth Token`);
}
if (tokenPayload.handle.toLowerCase() !== data.questioner.toLowerCase()) {
if (tokenPayload.handle !== data.questioner) {
throw new Error(`Token and questioner not match`);
}
} catch (err) {
Expand Down
24 changes: 5 additions & 19 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@ const mastodonAuth = async ({ host }: loginReqDto) => {

/**
* https://example.com/ 같은 URL 형식으로 온 경우 Host 형식으로 변환
* host형식으로 온 경우 그대로 반환
* 소문자 처리
* @param urlOrHost
* @returns
*/
function urlToHost(urlOrHost: string) {
function convertHost(urlOrHost: string) {
const re = /\/\/[^/@\s]+(:[0-9]{1,5})?\/?/;
const matched_str = urlOrHost.match(re)?.[0];
if (matched_str) {
console.log(`URL ${urlOrHost} replaced with ${matched_str.replaceAll('/', '')}`);
return matched_str.replaceAll('/', '');
return matched_str.replaceAll('/', '').toLowerCase();
}
return urlOrHost;
return urlOrHost.toLowerCase();
}

export default function Home() {
Expand All @@ -80,7 +80,7 @@ export default function Home() {

const onSubmit: SubmitHandler<FormValue> = async (e) => {
setIsLoading(true);
const host = urlToHost(e.address);
const host = convertHost(e.address);
localStorage.setItem('server', host);

detectInstance(host).then((type) => {
Expand All @@ -89,20 +89,7 @@ export default function Home() {
};
switch (type) {
case 'misskey':
localStorage.setItem('server', host);
misskeyAuth(payload)
.then((r) => {
setIsLoading(false);
router.replace(r.url);
})
.catch((err) => {
setIsLoading(false);
setErrorMessage(err);
errModalRef.current?.showModal();
});
break;
case 'cherrypick':
localStorage.setItem('server', host);
misskeyAuth(payload)
.then((r) => {
setIsLoading(false);
Expand All @@ -115,7 +102,6 @@ export default function Home() {
});
break;
case 'mastodon':
localStorage.setItem('server', host);
mastodonAuth(payload)
.then((r) => {
router.replace(r);
Expand Down

0 comments on commit 5b442a3

Please sign in to comment.