@@ -9,9 +9,15 @@ const DISCORD_WEBHOOK_URL_ACCESS_LOG = Deno.env.get(
99const DISCORD_WEBHOOK_URL_API_ACCESS_LOG = Deno . env . get (
1010 "DISCORD_WEBHOOK_URL_API_ACCESS_LOG" ,
1111) ;
12+ const DISCORD_WEBHOOK_URL_OTHERS_LOG = Deno . env . get (
13+ "DISCORD_WEBHOOK_URL_OTHERS_LOG" ,
14+ ) ;
1215
13- export const sendAccessLog = async ( c : Context ) => {
14- if ( ! DISCORD_WEBHOOK_URL_ACCESS_LOG ) return ;
16+ export const sendAccessLog = async ( c : Context , others : boolean ) => {
17+ const webhookURL = others
18+ ? DISCORD_WEBHOOK_URL_OTHERS_LOG
19+ : DISCORD_WEBHOOK_URL_ACCESS_LOG ;
20+ if ( ! webhookURL ) return ;
1521
1622 const info = getConnInfo ( c ) ;
1723 const time = new Date ( ) . toLocaleString ( "en-US" , {
@@ -24,18 +30,21 @@ export const sendAccessLog = async (c: Context) => {
2430 second : "numeric" ,
2531 } ) ;
2632
27- await sendDiscordWebhook ( DISCORD_WEBHOOK_URL_ACCESS_LOG , {
28- content : c . req . path ,
29- embeds : [
30- {
31- description : `[${ c . req . method } ] ${ c . req . url } ` ,
32- color : 0x008000 ,
33- footer : {
34- text : `${ time } - ${ info . remote . address } ` ,
33+ await sendDiscordWebhook (
34+ webhookURL ,
35+ {
36+ content : c . req . path ,
37+ embeds : [
38+ {
39+ description : `[${ c . req . method } ] ${ c . req . url } - ${ c . res . status } ` ,
40+ color : others ? 0xffff00 : 0x008000 ,
41+ footer : {
42+ text : `${ time } - ${ info . remote . address } ` ,
43+ } ,
3544 } ,
36- } ,
37- ] ,
38- } ) ;
45+ ] ,
46+ } ,
47+ ) ;
3948} ;
4049
4150export const sendAPIAccessLog = async (
@@ -51,9 +60,9 @@ export const sendAPIAccessLog = async (
5160 const encoder = new TextEncoder ( ) ;
5261 const data = encoder . encode ( apiKey ) ;
5362 const hash = await crypto . subtle . digest ( "SHA-256" , data ) ;
54- hashedApiKey = Array . from ( new Uint8Array ( hash ) ) . map ( ( b ) =>
55- b . toString ( 16 ) . padStart ( 2 , "0" )
56- ) . join ( "" ) ;
63+ hashedApiKey = Array . from ( new Uint8Array ( hash ) )
64+ . map ( ( b ) => b . toString ( 16 ) . padStart ( 2 , "0" ) )
65+ . join ( "" ) ;
5766 }
5867
5968 const info = getConnInfo ( c ) ;
@@ -73,10 +82,12 @@ export const sendAPIAccessLog = async (
7382 title,
7483 description : `[${ c . req . method } ] ${ c . req . url } ` ,
7584 color : error ? 0xff0000 : 0x008000 ,
76- fields : [ {
77- name : "Hashed API Key" ,
78- value : hashedApiKey ,
79- } ] ,
85+ fields : [
86+ {
87+ name : "Hashed API Key" ,
88+ value : hashedApiKey ,
89+ } ,
90+ ] ,
8091 footer : {
8192 text : `${ time } - ${ info . remote . address } ` ,
8293 } ,
0 commit comments