11use crate :: args:: { Args , ARGS } ;
22use crate :: endpoints:: errors:: ErrorTemplate ;
3- use crate :: util:: animalnumbers:: to_u64;
4- use crate :: util:: hashids:: to_u64 as hashid_to_u64;
3+ use crate :: util:: hashids:: alias_comparator;
54use crate :: util:: misc:: remove_expired;
65use crate :: AppState ;
76use actix_web:: { get, web, HttpResponse } ;
@@ -25,14 +24,10 @@ pub async fn auth_upload(data: web::Data<AppState>, id: web::Path<String>) -> Ht
2524
2625 remove_expired ( & mut pastas) ;
2726
28- let intern_id = if ARGS . hash_ids {
29- hashid_to_u64 ( & id) . unwrap_or ( 0 )
30- } else {
31- to_u64 ( & id) . unwrap_or ( 0 )
32- } ;
27+ let comparator = alias_comparator ( id. as_str ( ) ) ;
3328
3429 for ( _i, pasta) in pastas. iter ( ) . enumerate ( ) {
35- if pasta. id == intern_id {
30+ if comparator ( pasta) {
3631 return HttpResponse :: Ok ( ) . content_type ( "text/html; charset=utf-8" ) . body (
3732 AuthPasta {
3833 args : & ARGS ,
@@ -65,14 +60,10 @@ pub async fn auth_upload_with_status(
6560
6661 let ( id, status) = param. into_inner ( ) ;
6762
68- let intern_id = if ARGS . hash_ids {
69- hashid_to_u64 ( & id) . unwrap_or ( 0 )
70- } else {
71- to_u64 ( & id) . unwrap_or ( 0 )
72- } ;
63+ let comparator = alias_comparator ( id. as_str ( ) ) ;
7364
7465 for ( _i, pasta) in pastas. iter ( ) . enumerate ( ) {
75- if pasta. id == intern_id {
66+ if comparator ( pasta) {
7667 return HttpResponse :: Ok ( ) . content_type ( "text/html; charset=utf-8" ) . body (
7768 AuthPasta {
7869 args : & ARGS ,
@@ -100,14 +91,10 @@ pub async fn auth_raw_pasta(data: web::Data<AppState>, id: web::Path<String>) ->
10091
10192 remove_expired ( & mut pastas) ;
10293
103- let intern_id = if ARGS . hash_ids {
104- hashid_to_u64 ( & id) . unwrap_or ( 0 )
105- } else {
106- to_u64 ( & id) . unwrap_or ( 0 )
107- } ;
94+ let comparator = alias_comparator ( id. as_str ( ) ) ;
10895
10996 for ( _i, pasta) in pastas. iter ( ) . enumerate ( ) {
110- if pasta. id == intern_id {
97+ if comparator ( pasta) {
11198 return HttpResponse :: Ok ( ) . content_type ( "text/html; charset=utf-8" ) . body (
11299 AuthPasta {
113100 args : & ARGS ,
@@ -140,14 +127,10 @@ pub async fn auth_raw_pasta_with_status(
140127
141128 let ( id, status) = param. into_inner ( ) ;
142129
143- let intern_id = if ARGS . hash_ids {
144- hashid_to_u64 ( & id) . unwrap_or ( 0 )
145- } else {
146- to_u64 ( & id) . unwrap_or ( 0 )
147- } ;
130+ let comparator = alias_comparator ( id. as_str ( ) ) ;
148131
149132 for ( _i, pasta) in pastas. iter ( ) . enumerate ( ) {
150- if pasta. id == intern_id {
133+ if comparator ( pasta) {
151134 return HttpResponse :: Ok ( ) . content_type ( "text/html; charset=utf-8" ) . body (
152135 AuthPasta {
153136 args : & ARGS ,
@@ -175,14 +158,10 @@ pub async fn auth_edit_private(data: web::Data<AppState>, id: web::Path<String>)
175158
176159 remove_expired ( & mut pastas) ;
177160
178- let intern_id = if ARGS . hash_ids {
179- hashid_to_u64 ( & id) . unwrap_or ( 0 )
180- } else {
181- to_u64 ( & id) . unwrap_or ( 0 )
182- } ;
161+ let comparator = alias_comparator ( id. as_str ( ) ) ;
183162
184163 for ( _, pasta) in pastas. iter ( ) . enumerate ( ) {
185- if pasta. id == intern_id {
164+ if comparator ( pasta) {
186165 return HttpResponse :: Ok ( ) . content_type ( "text/html; charset=utf-8" ) . body (
187166 AuthPasta {
188167 args : & ARGS ,
@@ -215,14 +194,10 @@ pub async fn auth_edit_private_with_status(
215194
216195 let ( id, status) = param. into_inner ( ) ;
217196
218- let intern_id = if ARGS . hash_ids {
219- hashid_to_u64 ( & id) . unwrap_or ( 0 )
220- } else {
221- to_u64 ( & id) . unwrap_or ( 0 )
222- } ;
197+ let comparator = alias_comparator ( id. as_str ( ) ) ;
223198
224199 for ( _i, pasta) in pastas. iter ( ) . enumerate ( ) {
225- if pasta. id == intern_id {
200+ if comparator ( pasta) {
226201 return HttpResponse :: Ok ( ) . content_type ( "text/html; charset=utf-8" ) . body (
227202 AuthPasta {
228203 args : & ARGS ,
@@ -250,14 +225,10 @@ pub async fn auth_file(data: web::Data<AppState>, id: web::Path<String>) -> Http
250225
251226 remove_expired ( & mut pastas) ;
252227
253- let intern_id = if ARGS . hash_ids {
254- hashid_to_u64 ( & id) . unwrap_or ( 0 )
255- } else {
256- to_u64 ( & id) . unwrap_or ( 0 )
257- } ;
228+ let comparator = alias_comparator ( id. as_str ( ) ) ;
258229
259230 for ( _, pasta) in pastas. iter ( ) . enumerate ( ) {
260- if pasta. id == intern_id {
231+ if comparator ( pasta) {
261232 return HttpResponse :: Ok ( ) . content_type ( "text/html; charset=utf-8" ) . body (
262233 AuthPasta {
263234 args : & ARGS ,
@@ -290,14 +261,10 @@ pub async fn auth_file_with_status(
290261
291262 let ( id, status) = param. into_inner ( ) ;
292263
293- let intern_id = if ARGS . hash_ids {
294- hashid_to_u64 ( & id) . unwrap_or ( 0 )
295- } else {
296- to_u64 ( & id) . unwrap_or ( 0 )
297- } ;
264+ let comparator = alias_comparator ( id. as_str ( ) ) ;
298265
299266 for ( _i, pasta) in pastas. iter ( ) . enumerate ( ) {
300- if pasta. id == intern_id {
267+ if comparator ( pasta) {
301268 return HttpResponse :: Ok ( ) . content_type ( "text/html; charset=utf-8" ) . body (
302269 AuthPasta {
303270 args : & ARGS ,
@@ -325,14 +292,10 @@ pub async fn auth_remove_private(data: web::Data<AppState>, id: web::Path<String
325292
326293 remove_expired ( & mut pastas) ;
327294
328- let intern_id = if ARGS . hash_ids {
329- hashid_to_u64 ( & id) . unwrap_or ( 0 )
330- } else {
331- to_u64 ( & id) . unwrap_or ( 0 )
332- } ;
295+ let comparator = alias_comparator ( id. as_str ( ) ) ;
333296
334297 for ( _, pasta) in pastas. iter ( ) . enumerate ( ) {
335- if pasta. id == intern_id {
298+ if comparator ( pasta) {
336299 return HttpResponse :: Ok ( ) . content_type ( "text/html; charset=utf-8" ) . body (
337300 AuthPasta {
338301 args : & ARGS ,
@@ -365,14 +328,10 @@ pub async fn auth_remove_private_with_status(
365328
366329 let ( id, status) = param. into_inner ( ) ;
367330
368- let intern_id = if ARGS . hash_ids {
369- hashid_to_u64 ( & id) . unwrap_or ( 0 )
370- } else {
371- to_u64 ( & id) . unwrap_or ( 0 )
372- } ;
331+ let comparator = alias_comparator ( id. as_str ( ) ) ;
373332
374333 for ( _i, pasta) in pastas. iter ( ) . enumerate ( ) {
375- if pasta. id == intern_id {
334+ if comparator ( pasta) {
376335 return HttpResponse :: Ok ( ) . content_type ( "text/html; charset=utf-8" ) . body (
377336 AuthPasta {
378337 args : & ARGS ,
0 commit comments