Commit 09d0aa4d authored by nanahira's avatar nanahira

ci

parent ce0c07b5
......@@ -29,7 +29,8 @@ build_mycard:
extends: .build
variables:
TARGET: mycard
NEXT_PUBLIC_BACKEND_URL: https://nai-api.moecube.com:444
NOVELAI_BACKEND_URL: https://nai-api.moecube.com:444
NOVELAI_MYCARD: 1
upload_to_minio:
stage: deploy
......
......@@ -39,7 +39,7 @@ const sharedConfig = {
poweredByHeader: false,
env: {
NEXT_PUBLIC_COMMITHASH: commithash.slice(0, 7),
NEXT_PUBLIC_BACKEND_URL: process.env.NOVELAI_BACKEND_URL,
NEXT_PUBLIC_BACKEND_URL: process.env.NOVELAI_BACKEND_URL, // Backend URL
NEXT_PUBLIC_ENVIRONMENT: process.env.NOVELAI_ENVIRONMENT,
NEXT_PUBLIC_MOCK_ENV: process.env.NOVELAI_MOCK_ENV,
NEXT_PUBLIC_RECAPTCHA_KEY: process.env.NOVELAI_RECAPTCHA_KEY,
......@@ -52,7 +52,8 @@ const sharedConfig = {
NEXT_PUBLIC_PADDLE_GIFTKEY_TABLET_ID: process.env.NOVELAI_PADDLE_GIFTKEY_TABLET_ID,
NEXT_PUBLIC_PADDLE_GIFTKEY_SCROLL_ID: process.env.NOVELAI_PADDLE_GIFTKEY_SCROLL_ID,
NEXT_PUBLIC_PADDLE_GIFTKEY_OPUS_ID: process.env.NOVELAI_PADDLE_GIFTKEY_OPUS_ID,
NEXT_PUBLIC_TOKEN: process.env.NOVELAI_TOKEN,
NEXT_PUBLIC_TOKEN: process.env.NOVELAI_TOKEN, // Static token
NEXT_PUBLIC_MYCARD: process.env.NOVELAI_MYCARD, // Enable MyCard auth
},
productionBrowserSourceMaps: true,
generateBuildId: () => commithash.slice(0, 7) + '-' + process.env.NOVELAI_ENVIRONMENT,
......
......@@ -27,6 +27,7 @@ specifiers:
'@types/webpack-env': ^1.18.0
'@typescript-eslint/eslint-plugin': ^5.38.1
'@typescript-eslint/parser': ^5.38.1
buffer: ^6.0.3
chardet: ^1.4.0
compromise: ^14.5.0
concurrently: ^7.4.0
......@@ -119,6 +120,7 @@ dependencies:
'@sentry/nextjs': 7.14.1_4xhv7cfxlomhx5mtnmxlys2rom
'@sentry/tracing': 7.14.1
'@szhsin/react-menu': 3.2.0_biqbaboplfbrettd7655fr4n2y
buffer: 6.0.3
chardet: 1.4.0
compromise: 14.5.0
dayjs: 1.11.5
......@@ -3224,6 +3226,10 @@ packages:
/balanced-match/1.0.2:
resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==}
/base64-js/1.5.1:
resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==}
dev: false
/bn.js/4.12.0:
resolution: {integrity: sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==}
dev: true
......@@ -3321,6 +3327,13 @@ packages:
resolution: {integrity: sha512-571s0T7nZWK6vB67HI5dyUF7wXiNcfaPPPTl6zYCNApANjIvYJTg7hlud/+cJpdAhS7dVzqMLmfhfHR3rAcOjQ==}
dev: true
/buffer/6.0.3:
resolution: {integrity: sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==}
dependencies:
base64-js: 1.5.1
ieee754: 1.2.1
dev: false
/builtin-modules/3.3.0:
resolution: {integrity: sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==}
engines: {node: '>=6'}
......@@ -5130,6 +5143,10 @@ packages:
resolution: {integrity: sha512-Wsk07aAxDsntgYJY4h0knZJuTxM73eQ4reRAO+Z1liOh8eMCJ/MoDS8fCui1vGT9mnjtl1sOu3I2i/W1swPYZg==}
dev: false
/ieee754/1.2.1:
resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==}
dev: false
/ignore/5.2.0:
resolution: {integrity: sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==}
engines: {node: '>= 4'}
......
import { mycard } from '../util/mycard'
export const Environment = process.env.NEXT_PUBLIC_ENVIRONMENT || 'debug'
export const CommitHash = process.env.NEXT_PUBLIC_COMMITHASH || 'unknown'
export const SentryDSN = process.env.NEXT_PUBLIC_SENTRY_DSN || ''
export const BackendURL = process.env.NEXT_PUBLIC_BACKEND_URL || ''
export const BackendToken = process.env.NEXT_PUBLIC_BACKEND_TOKEN || ''
export const BackendToken = mycard.getToken() || process.env.NEXT_PUBLIC_BACKEND_TOKEN || ''
export const MockEnv = process.env.NEXT_PUBLIC_MOCK_ENV === 'true'
export const RecaptchaKey = process.env.NEXT_PUBLIC_RECAPTCHA_KEY || ''
export const PaddleSandbox = process.env.NEXT_PUBLIC_PADDLE_SANDBOX === 'true'
......
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { Buffer } from 'buffer'
import { useEffect } from 'react'
function loginUrl(callbackUrl: string) {
let params = new URLSearchParams()
params.set('return_sso_url', callbackUrl)
const payload = Buffer.from(params.toString()).toString('base64')
const url = new URL('https://accounts.moecube.com/signin')
params = url['searchParams']
params.set('sso', payload)
return url.toString()
}
interface MyCardSSOUser {
id: string
username: string
name: string
email: string
password_hash: string
salt: string
active: string
admin: string
avatar: string
locale: string
registration_ip_address: string
ip_address: string
created_at: string
updated_at: string
return_sso_url: string
external_id: string
avatar_url: string
avatar_force_update: string
token: string
}
export class MyCard {
user: MyCardSSOUser
isActive: boolean
constructor() {
if (!process.env.NEXT_PUBLIC_MYCARD || typeof window === 'undefined') {
this.isActive = false
return
}
this.isActive = true
const ssoString = new URLSearchParams(window.location.search).get('sso')
const loginString = ssoString || window.localStorage.getItem('mycardLogin')
if (!loginString) {
return
}
window.localStorage.setItem('mycardLogin', loginString)
const decodedLoginString = Buffer.from(loginString, 'base64').toString()
const params = new URLSearchParams(decodedLoginString)
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
this.user = Object.fromEntries(params)
}
login() {
const currentUrl = window.location.href
window.location.replace(loginUrl(currentUrl))
}
getToken() {
if (!this.user) {
if (this.isActive) {
this.login()
}
return ''
}
return this.user.token
}
logout() {
window.localStorage.removeItem('mycardLogin')
this.login()
}
}
export const mycard = new MyCard()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment