Skip to content

Commit

Permalink
feat: 로깅 개선
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoto-Cocoa committed Jul 11, 2023
1 parent 72876bc commit fa6bba1
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export async function handler(event: APIGatewayProxyEventV2WithRequestContext<AP
const targetNote = note.renote ?? note;
const chunks = [ note.renote?.text ?? note.text ?? '' ];

console.log(`Request from ${note.user.username}@${host}`)
console.log(`Request from ${note.user.id}@${host} (@${note.user.username}@${host})`)

if (!isValidRequest(note)) {
return buildResponse({
Expand All @@ -78,6 +78,8 @@ export async function handler(event: APIGatewayProxyEventV2WithRequestContext<AP
}

if (event.headers['x-misskey-hook-secret'] !== user.secret) {
console.log(`Invalid secret; Expected ${user.secret}, got ${event.headers['x-misskey-hook-secret']}`);

return buildResponse({
statusCode: 200,
body: JSON.stringify({
Expand Down Expand Up @@ -148,6 +150,8 @@ export async function handler(event: APIGatewayProxyEventV2WithRequestContext<AP
const twitterApiConf = user.twitterApiConfs.find(conf => conf.visibility === note.visibility);

if (!twitterApiConf) {
console.log(`Twitter API conf not found for visibility ${note.visibility}`);

return buildResponse({
statusCode: 200,
body: JSON.stringify({
Expand Down Expand Up @@ -380,14 +384,20 @@ function joinTags(tags: Set<string>): string {

function isValidRequest(note: WebhookNote): boolean {
if (note.mentions?.length > 0) {
return false
console.log('Mentions found; skipping');

return false;
}

if (note.reply) {
console.log('Reply found; skipping');

return false;
}

if (note.visibility === 'specified') {
console.log('Specified visibility found; skipping');

return false;
}

Expand Down

0 comments on commit fa6bba1

Please sign in to comment.