ai/at
1
0

fix ozone

This commit is contained in:
2025-12-03 23:11:38 +09:00
parent a837c79f43
commit ce9abf1ef9
12 changed files with 251 additions and 177 deletions

View File

@@ -1,99 +1,8 @@
--- a/lib/constants.ts
+++ b/lib/constants.ts
@@ -1,29 +1,32 @@
+import { env } from 'next-runtime-env';
@@ -1,3 +1,5 @@
+import { env } from 'next-runtime-env'
+
export const OAUTH_SCOPE = 'atproto transition:generic transition:chat.bsky'
export const OZONE_SERVICE_DID =
- process.env.NEXT_PUBLIC_OZONE_SERVICE_DID || undefined
+ env('NEXT_PUBLIC_OZONE_SERVICE_DID') || undefined
export const OZONE_PUBLIC_URL =
- process.env.NEXT_PUBLIC_OZONE_PUBLIC_URL || undefined
+ env('NEXT_PUBLIC_OZONE_PUBLIC_URL') || undefined
export const PLC_DIRECTORY_URL =
- process.env.NEXT_PUBLIC_PLC_DIRECTORY_URL ||
+ env('NEXT_PUBLIC_PLC_DIRECTORY_URL') ||
(process.env.NODE_ENV === 'development'
? 'http://localhost:2582'
: 'https://plc.directory')
-export const QUEUE_CONFIG = process.env.NEXT_PUBLIC_QUEUE_CONFIG || '{}'
+export const QUEUE_CONFIG = env('NEXT_PUBLIC_QUEUE_CONFIG') || '{}'
-export const QUEUE_SEED = process.env.NEXT_PUBLIC_QUEUE_SEED || ''
+export const QUEUE_SEED = env('NEXT_PUBLIC_QUEUE_SEED') || ''
+export const SOCIAL_APP_DOMAIN = env('NEXT_PUBLIC_SOCIAL_APP_DOMAIN') || 'bsky.app'
export const SOCIAL_APP_URL =
- process.env.NEXT_PUBLIC_SOCIAL_APP_URL ||
+ env('NEXT_PUBLIC_SOCIAL_APP_URL') ||
(process.env.NODE_ENV === 'development'
? 'http://localhost:2584'
- : 'https://bsky.app')
+ : `https://${SOCIAL_APP_DOMAIN}`)
export const HANDLE_RESOLVER_URL =
- process.env.NEXT_PUBLIC_HANDLE_RESOLVER_URL ||
+ env('NEXT_PUBLIC_HANDLE_RESOLVER_URL') ||
(process.env.NODE_ENV === 'development'
? 'http://localhost:2584'
: 'https://api.bsky.app')
@@ -36,25 +39,25 @@
export const NEW_ACCOUNT_MARKER_THRESHOLD_IN_DAYS = process.env
.NEXT_PUBLIC_NEW_ACCOUNT_MARKER_THRESHOLD_IN_DAYS
- ? parseInt(process.env.NEXT_PUBLIC_NEW_ACCOUNT_MARKER_THRESHOLD_IN_DAYS)
+ ? parseInt(env('NEXT_PUBLIC_NEW_ACCOUNT_MARKER_THRESHOLD_IN_DAYS'))
: 7
export const YOUNG_ACCOUNT_MARKER_THRESHOLD_IN_DAYS = process.env
.NEXT_PUBLIC_YOUNG_ACCOUNT_MARKER_THRESHOLD_IN_DAYS
- ? parseInt(process.env.NEXT_PUBLIC_YOUNG_ACCOUNT_MARKER_THRESHOLD_IN_DAYS)
+ ? parseInt(env('NEXT_PUBLIC_YOUNG_ACCOUNT_MARKER_THRESHOLD_IN_DAYS'))
: 30
export const DOMAINS_ALLOWING_EMAIL_COMMUNICATION = (
- process.env.NEXT_PUBLIC_DOMAINS_ALLOWING_EMAIL_COMMUNICATION || ''
+ env('NEXT_PUBLIC_DOMAINS_ALLOWING_EMAIL_COMMUNICATION') || ''
).split(',')
export const HIGH_PROFILE_FOLLOWER_THRESHOLD = process.env
.NEXT_PUBLIC_HIGH_PROFILE_FOLLOWER_THRESHOLD
- ? parseInt(process.env.NEXT_PUBLIC_HIGH_PROFILE_FOLLOWER_THRESHOLD)
+ ? parseInt(env('NEXT_PUBLIC_HIGH_PROFILE_FOLLOWER_THRESHOLD'))
: Infinity
export const FALLBACK_VIDEO_URL = (
- process.env.NEXT_PUBLIC_FALLBACK_VIDEO_URL || ''
+ env('NEXT_PUBLIC_FALLBACK_VIDEO_URL') || ''
).split(':')
// strike to account suspension duration mapping (in hours)
@@ -87,18 +90,18 @@
export const STRIKE_TO_SUSPENSION_DURATION_IN_HOURS =
parseStrikeSuspensionConfig(
- process.env.NEXT_PUBLIC_STRIKE_SUSPENSION_CONFIG || '',
+ env('NEXT_PUBLIC_STRIKE_SUSPENSION_CONFIG') || '',
)
export const AUTOMATED_ACTION_EMAIL_IDS = {
warningWithTakedown:
- process.env.NEXT_PUBLIC_WARNING_WITH_TAKEDOWN_EMAIL_TEMPLATE_ID,
+ env('NEXT_PUBLIC_WARNING_WITH_TAKEDOWN_EMAIL_TEMPLATE_ID'),
suspensionWithTakedown:
- process.env.NEXT_PUBLIC_SUSPENSION_WITH_TAKEDOWN_EMAIL_TEMPLATE_ID,
+ env('NEXT_PUBLIC_SUSPENSION_WITH_TAKEDOWN_EMAIL_TEMPLATE_ID'),
suspensionWithoutTakedown:
- process.env.NEXT_PUBLIC_SUSPENSION_WITHOUT_TAKEDOWN_EMAIL_TEMPLATE_ID,
+ env('NEXT_PUBLIC_SUSPENSION_WITHOUT_TAKEDOWN_EMAIL_TEMPLATE_ID'),
permanentTakedown:
- process.env.NEXT_PUBLIC_PERMANENT_TAKEDOWN_EMAIL_TEMPLATE_ID,
+ env('NEXT_PUBLIC_PERMANENT_TAKEDOWN_EMAIL_TEMPLATE_ID'),
takedownWithoutStrike:
- process.env.NEXT_PUBLIC_TAKEDOWN_WITHOUT_STRIKE_EMAIL_TEMPLATE_ID,
+ env('NEXT_PUBLIC_TAKEDOWN_WITHOUT_STRIKE_EMAIL_TEMPLATE_ID'),
}

View File

@@ -1,5 +1,5 @@
diff --git a/service/index.js b/service/index.js
index 943c281..7721cd9 100644
index d5295a3..7721cd9 100644
--- a/service/index.js
+++ b/service/index.js
@@ -1,5 +1,7 @@
@@ -19,7 +19,7 @@ index 943c281..7721cd9 100644
const pkg = require('@atproto/ozone/package.json')
async function main() {
@@ -16,37 +19,48 @@ async function main() {
@@ -16,30 +19,48 @@ async function main() {
const frontendHandler = frontend.getRequestHandler()
await frontend.prepare()
// backend
@@ -41,19 +41,16 @@ index 943c281..7721cd9 100644
await db.close()
}
- const ozone = await OzoneService.create(config, secrets)
-
+ const server = await ozone.OzoneService.create(config, secrets)
// setup handlers
- ozone.app.get('/.well-known/ozone-metadata.json', (_req, res) => {
+ // setup handlers
+ server.app.get('/.well-known/ozone-metadata.json', (_req, res) => {
return res.json({
- did: ozone.ctx.cfg.service.did,
- url: ozone.ctx.cfg.service.publicUrl,
- publicKey: ozone.ctx.signingKey.did(),
+ return res.json({
+ did: server.ctx.cfg.service.did,
+ url: server.ctx.cfg.service.publicUrl,
+ publicKey: server.ctx.signingKey.did(),
})
})
+ })
+ })
// Note: We must use `use()` here. This should be the last middleware.
- ozone.app.use((req, res) => {
+ server.app.use((req, res) => {

View File

@@ -0,0 +1,27 @@
--- a/components/shell/ConfigurationFlow.tsx
+++ b/components/shell/ConfigurationFlow.tsx
@@ -97,22 +97,6 @@ export function ConfigurationFlow({
}
if (config.needs.key || config.needs.service) {
- if (authDid !== config.did) {
- return (
- <>
- <ErrorInfo type="warn" className="mt-2">
- {`You're`} logged in as {authIdentifier}. Please login as{' '}
- {config.handle || 'your Ozone service account'} in order to
- configure Ozone.
- </ErrorInfo>
- <Button
- className="w-full mt-2"
- icon={<ArrowLeftOnRectangleIcon />}
- onClick={signOut}
- >
- Restart
- </Button>
- </>
- )
- }
if (config.did.startsWith('did:web:')) {
return (
<>

View File

@@ -0,0 +1,61 @@
diff --git a/components/shell/ConfigurationFlow.tsx b/components/shell/ConfigurationFlow.tsx
index 7280a7b..0bb4e14 100644
--- a/components/shell/ConfigurationFlow.tsx
+++ b/components/shell/ConfigurationFlow.tsx
@@ -97,43 +97,6 @@ export function ConfigurationFlow({
}
if (config.needs.key || config.needs.service) {
- if (authDid !== config.did) {
- return (
- <>
- <ErrorInfo type="warn" className="mt-2">
- {`You're`} logged in as {authIdentifier}. Please login as{' '}
- {config.handle || 'your Ozone service account'} in order to
- configure Ozone.
- </ErrorInfo>
- <Button
- className="w-full mt-2"
- icon={<ArrowLeftOnRectangleIcon />}
- onClick={signOut}
- >
- Restart
- </Button>
- </>
- )
- }
- if (config.did.startsWith('did:web:')) {
- return (
- <>
- <ErrorInfo type="warn" className="mt-2">
- You must configure your identity on your own if {`you're`} using a
- did:web. You will need to add a service with id{' '}
- {`"atproto_labeler"`} and verification method with id{' '}
- {`"atproto_label"`}.
- </ErrorInfo>
- <Button
- className="w-full mt-2"
- icon={<ArrowLeftOnRectangleIcon />}
- onClick={signOut}
- >
- Restart
- </Button>
- </>
- )
- }
if (!config.doc) {
return (
<>
diff --git a/lib/identity.ts b/lib/identity.ts
index a8ec3a7..8e4d171 100644
--- a/lib/identity.ts
+++ b/lib/identity.ts
@@ -83,7 +83,7 @@ export function didDocToData(doc: {
const [, id] = s['id'].split('#')
acc[id] = {
type: s['type'],
- serviceEndpoint: s['serviceEndpoint'],
+ endpoint: s['serviceEndpoint'],
}
}
return acc

View File

@@ -0,0 +1,13 @@
diff --git a/app/oauth-client.json/route.ts b/app/oauth-client.json/route.ts
index 4755046..c602676 100644
--- a/app/oauth-client.json/route.ts
+++ b/app/oauth-client.json/route.ts
@@ -20,7 +20,7 @@ export async function GET(request: Request) {
oauthClientMetadataSchema.parse({
client_id: requestUrl.href,
client_uri: new URL('/', requestUrl).href,
- redirect_uris: [new URL('/', requestUrl).href],
+ redirect_uris: [new URL('/oauth/callback', requestUrl).href],
response_types: ['code'],
grant_types: ['authorization_code', 'refresh_token'],
token_endpoint_auth_method: 'none',

View File

@@ -0,0 +1,13 @@
diff --git a/packages/oauth/oauth-provider/src/router/create-authorization-page-middleware.ts b/packages/oauth/oauth-provider/src/router/create-authorization-page-middleware.ts
index f653b0353..45c45fac1 100644
--- a/packages/oauth/oauth-provider/src/router/create-authorization-page-middleware.ts
+++ b/packages/oauth/oauth-provider/src/router/create-authorization-page-middleware.ts
@@ -53,7 +53,7 @@ export function createAuthorizationPageMiddleware<
res.setHeader('Cache-Control', 'no-store')
res.setHeader('Pragma', 'no-cache')
- validateFetchSite(req, ['cross-site', 'none'])
+ validateFetchSite(req, ['cross-site', 'same-site', 'none'])
validateFetchMode(req, ['navigate'])
validateFetchDest(req, ['document'])
validateOrigin(req, issuerOrigin)

View File

@@ -0,0 +1,22 @@
diff --git a/src/lib/statsig/statsig.tsx b/src/lib/statsig/statsig.tsx
index 1234567..89abcdef 100644
--- a/src/lib/statsig/statsig.tsx
+++ b/src/lib/statsig/statsig.tsx
@@ -266,6 +266,7 @@ export async function tryFetchGates(
}
export function initialize() {
+ if (!SDK_KEY) return Promise.resolve()
return Statsig.initialize(SDK_KEY, null, createStatsigOptions([]))
}
@@ -310,6 +311,9 @@ export function Provider({children}: {children: React.ReactNode}) {
return () => clearInterval(id)
}, [handleIntervalTick])
+ if (!SDK_KEY) {
+ return <GateCache.Provider value={gateCache}>{children}</GateCache.Provider>
+ }
return (
<GateCache.Provider value={gateCache}>
<StatsigProvider