@@ -57,6 +57,7 @@ import {
57
57
} from "../../schema" ;
58
58
import { disk , getAssetUrl } from "../../storage" ;
59
59
import { extractCustomEmojis , formatText } from "../../text" ;
60
+ import { type Uuid , isUuid , uuid } from "../../uuid" ;
60
61
import { timelineQuerySchema } from "./timelines" ;
61
62
62
63
const app = new Hono < { Variables : Variables } > ( ) ;
@@ -265,7 +266,7 @@ app.get(
265
266
422 ,
266
267
) ;
267
268
}
268
- const ids = c . req . queries ( "id[]" ) ?? [ ] ;
269
+ const ids = ( c . req . queries ( "id[]" ) ?? [ ] ) . filter ( isUuid ) ;
269
270
const accountList =
270
271
ids . length > 0
271
272
? await db . query . accounts . findMany ( {
@@ -448,7 +449,7 @@ app.get(
448
449
422 ,
449
450
) ;
450
451
}
451
- const ids : string [ ] = c . req . queries ( "id[]" ) ?? [ ] ;
452
+ const ids : Uuid [ ] = ( c . req . queries ( "id[]" ) ?? [ ] ) . filter ( isUuid ) ;
452
453
const result : {
453
454
id : string ;
454
455
accounts : ReturnType < typeof serializeAccount > [ ] ;
@@ -488,6 +489,7 @@ app.get(
488
489
489
490
app . get ( "/:id" , async ( c ) => {
490
491
const id = c . req . param ( "id" ) ;
492
+ if ( ! isUuid ( id ) ) return c . json ( { error : "Record not found" } , 404 ) ;
491
493
const account = await db . query . accounts . findFirst ( {
492
494
where : eq ( accounts . id , id ) ,
493
495
with : { owner : true , successor : true } ,
@@ -518,14 +520,15 @@ app.get(
518
520
) ,
519
521
) ,
520
522
async ( c ) => {
523
+ const id = c . req . param ( "id" ) ;
524
+ if ( ! isUuid ( id ) ) return c . json ( { error : "Record not found" } , 404 ) ;
521
525
const tokenOwner = c . get ( "token" ) . accountOwner ;
522
526
if ( tokenOwner == null ) {
523
527
return c . json (
524
528
{ error : "This method requires an authenticated user" } ,
525
529
422 ,
526
530
) ;
527
531
}
528
- const id = c . req . param ( "id" ) ;
529
532
const account = await db . query . accounts . findFirst ( {
530
533
where : eq ( accounts . id , id ) ,
531
534
with : {
@@ -687,14 +690,15 @@ app.post(
687
690
tokenRequired ,
688
691
scopeRequired ( [ "write:follows" ] ) ,
689
692
async ( c ) => {
693
+ const id = c . req . param ( "id" ) ;
694
+ if ( ! isUuid ( id ) ) return c . json ( { error : "Record not found" } , 404 ) ;
690
695
const owner = c . get ( "token" ) . accountOwner ;
691
696
if ( owner == null ) {
692
697
return c . json (
693
698
{ error : "This method requires an authenticated user" } ,
694
699
422 ,
695
700
) ;
696
701
}
697
- const id = c . req . param ( "id" ) ;
698
702
const following = await db . query . accounts . findFirst ( {
699
703
where : eq ( accounts . id , id ) ,
700
704
with : { owner : true } ,
@@ -740,14 +744,15 @@ app.post(
740
744
tokenRequired ,
741
745
scopeRequired ( [ "write:follows" ] ) ,
742
746
async ( c ) => {
747
+ const id = c . req . param ( "id" ) ;
748
+ if ( ! isUuid ( id ) ) return c . json ( { error : "Record not found" } , 404 ) ;
743
749
const owner = c . get ( "token" ) . accountOwner ;
744
750
if ( owner == null ) {
745
751
return c . json (
746
752
{ error : "This method requires an authenticated user" } ,
747
753
422 ,
748
754
) ;
749
755
}
750
- const id = c . req . param ( "id" ) ;
751
756
const following = await db . query . accounts . findFirst ( {
752
757
where : eq ( accounts . id , id ) ,
753
758
with : { owner : true } ,
@@ -782,6 +787,7 @@ app.post(
782
787
783
788
app . get ( "/:id/followers" , async ( c ) => {
784
789
const accountId = c . req . param ( "id" ) ;
790
+ if ( ! isUuid ( accountId ) ) return c . json ( { error : "Record not found" } , 404 ) ;
785
791
const followers = await db . query . follows . findMany ( {
786
792
where : and ( eq ( follows . followingId , accountId ) , isNotNull ( follows . approved ) ) ,
787
793
orderBy : desc ( follows . approved ) ,
@@ -801,6 +807,7 @@ app.get("/:id/followers", async (c) => {
801
807
802
808
app . get ( "/:id/following" , async ( c ) => {
803
809
const accountId = c . req . param ( "id" ) ;
810
+ if ( ! isUuid ( accountId ) ) return c . json ( { error : "Record not found" } , 404 ) ;
804
811
const followers = await db . query . follows . findMany ( {
805
812
where : and ( eq ( follows . followerId , accountId ) , isNotNull ( follows . approved ) ) ,
806
813
orderBy : desc ( follows . approved ) ,
@@ -823,6 +830,8 @@ app.get(
823
830
tokenRequired ,
824
831
scopeRequired ( [ "read:lists" ] ) ,
825
832
async ( c ) => {
833
+ const accountId = c . req . param ( "id" ) ;
834
+ if ( ! isUuid ( accountId ) ) return c . json ( { error : "Record not found" } , 404 ) ;
826
835
const owner = c . get ( "token" ) . accountOwner ;
827
836
if ( owner == null ) {
828
837
return c . json (
@@ -838,7 +847,7 @@ app.get(
838
847
db
839
848
. select ( { id : listMembers . listId } )
840
849
. from ( listMembers )
841
- . where ( eq ( listMembers . accountId , c . req . param ( "id" ) ) ) ,
850
+ . where ( eq ( listMembers . accountId , accountId ) ) ,
842
851
) ,
843
852
) ,
844
853
} ) ;
@@ -853,8 +862,8 @@ app.get(
853
862
zValidator (
854
863
"query" ,
855
864
z . object ( {
856
- max_id : z . string ( ) . uuid ( ) . optional ( ) ,
857
- since_id : z . string ( ) . uuid ( ) . optional ( ) ,
865
+ max_id : uuid . optional ( ) ,
866
+ since_id : uuid . optional ( ) ,
858
867
limit : z
859
868
. string ( )
860
869
. default ( "40" )
@@ -911,15 +920,15 @@ app.post(
911
920
} ) ,
912
921
) ,
913
922
async ( c ) => {
923
+ const id = c . req . param ( "id" ) ;
924
+ if ( ! isUuid ( id ) ) return c . json ( { error : "Record not found" } , 404 ) ;
914
925
const owner = c . get ( "token" ) . accountOwner ;
915
-
916
926
if ( owner == null ) {
917
927
return c . json (
918
928
{ error : "This method requires an authenticated user" } ,
919
929
422 ,
920
930
) ;
921
931
}
922
- const id = c . req . param ( "id" ) ;
923
932
const { notifications, duration } = c . req . valid ( "json" ) ;
924
933
const account = await db . query . accounts . findFirst ( {
925
934
where : eq ( accounts . id , id ) ,
@@ -983,14 +992,15 @@ app.post(
983
992
tokenRequired ,
984
993
scopeRequired ( [ "write:mutes" ] ) ,
985
994
async ( c ) => {
995
+ const id = c . req . param ( "id" ) ;
996
+ if ( ! isUuid ( id ) ) return c . json ( { error : "Record not found" } , 404 ) ;
986
997
const owner = c . get ( "token" ) . accountOwner ;
987
998
if ( owner == null ) {
988
999
return c . json (
989
1000
{ error : "This method requires an authenticated user" } ,
990
1001
422 ,
991
1002
) ;
992
1003
}
993
- const id = c . req . param ( "id" ) ;
994
1004
await db
995
1005
. delete ( mutes )
996
1006
. where ( and ( eq ( mutes . accountId , owner . id ) , eq ( mutes . mutedAccountId , id ) ) ) ;
@@ -1024,14 +1034,15 @@ app.post(
1024
1034
tokenRequired ,
1025
1035
scopeRequired ( [ "read:blocks" ] ) ,
1026
1036
async ( c ) => {
1037
+ const id = c . req . param ( "id" ) ;
1038
+ if ( ! isUuid ( id ) ) return c . json ( { error : "Record not found" } , 404 ) ;
1027
1039
const owner = c . get ( "token" ) . accountOwner ;
1028
1040
if ( owner == null ) {
1029
1041
return c . json (
1030
1042
{ error : "This method requires an authenticated user" } ,
1031
1043
422 ,
1032
1044
) ;
1033
1045
}
1034
- const id = c . req . param ( "id" ) ;
1035
1046
const acct = await db . query . accounts . findFirst ( {
1036
1047
where : eq ( accounts . id , id ) ,
1037
1048
with : { owner : true } ,
@@ -1069,14 +1080,15 @@ app.post(
1069
1080
tokenRequired ,
1070
1081
scopeRequired ( [ "read:blocks" ] ) ,
1071
1082
async ( c ) => {
1083
+ const id = c . req . param ( "id" ) ;
1084
+ if ( ! isUuid ( id ) ) return c . json ( { error : "Record not found" } , 404 ) ;
1072
1085
const owner = c . get ( "token" ) . accountOwner ;
1073
1086
if ( owner == null ) {
1074
1087
return c . json (
1075
1088
{ error : "This method requires an authenticated user" } ,
1076
1089
422 ,
1077
1090
) ;
1078
1091
}
1079
- const id = c . req . param ( "id" ) ;
1080
1092
const acct = await db . query . accounts . findFirst ( {
1081
1093
where : eq ( accounts . id , id ) ,
1082
1094
with : { owner : true } ,
0 commit comments