@@ -64,44 +64,44 @@ pub async fn add_link(
6464 let result = utils:: is_api_ok ( http, config) ;
6565 // If success, add new link
6666 if result. success {
67- let out = utils:: add_link ( req, & data. db , config) ;
68- if out . 0 {
67+ let ( success , reason , expiry_time ) = utils:: add_link ( req, & data. db , config) ;
68+ if success {
6969 let site_url = config. site_url . clone ( ) ;
7070 let shorturl = if let Some ( url) = site_url {
71- format ! ( "{url}/{}" , out . 1 )
71+ format ! ( "{url}/{}" , reason )
7272 } else {
7373 let protocol = if config. port == 443 { "https" } else { "http" } ;
7474 let port_text = if [ 80 , 443 ] . contains ( & config. port ) {
7575 String :: new ( )
7676 } else {
7777 format ! ( ":{}" , config. port)
7878 } ;
79- format ! ( "{protocol}://localhost{port_text}/{}" , out . 1 )
79+ format ! ( "{protocol}://localhost{port_text}/{}" , reason )
8080 } ;
8181 let response = CreatedURL {
8282 success : true ,
8383 error : false ,
8484 shorturl,
85- expiry_time : out . 2 ,
85+ expiry_time,
8686 } ;
8787 HttpResponse :: Created ( ) . json ( response)
8888 } else {
8989 let response = Response {
9090 success : false ,
9191 error : true ,
92- reason : out . 1 ,
92+ reason,
9393 } ;
9494 HttpResponse :: Conflict ( ) . json ( response)
9595 }
9696 } else if result. error {
9797 HttpResponse :: Unauthorized ( ) . json ( result)
9898 // If password authentication or public mode is used - keeps backwards compatibility
9999 } else if config. public_mode || auth:: validate ( session, config) {
100- let out = utils:: add_link ( req, & data. db , config) ;
101- if out . 0 {
102- HttpResponse :: Created ( ) . body ( out . 1 )
100+ let ( success , reason , _ ) = utils:: add_link ( req, & data. db , config) ;
101+ if success {
102+ HttpResponse :: Created ( ) . body ( reason )
103103 } else {
104- HttpResponse :: Conflict ( ) . body ( out . 1 )
104+ HttpResponse :: Conflict ( ) . body ( reason )
105105 }
106106 } else {
107107 HttpResponse :: Unauthorized ( ) . body ( "Not logged in!" )
@@ -141,17 +141,14 @@ pub async fn getall(
141141pub async fn expand ( req : String , data : web:: Data < AppState > , http : HttpRequest ) -> HttpResponse {
142142 let result = utils:: is_api_ok ( http, & data. config ) ;
143143 if result. success {
144- let linkinfo = utils:: get_longurl ( req, & data. db , true ) ;
145- if let Some ( longlink) = linkinfo . 0 {
144+ let ( longurl , hits , expiry_time ) = utils:: get_longurl ( req, & data. db , true ) ;
145+ if let Some ( longlink) = longurl {
146146 let body = LinkInfo {
147147 success : true ,
148148 error : false ,
149149 longurl : longlink,
150- hits : linkinfo
151- . 1
152- . expect ( "Error getting hit count for existing shortlink." ) ,
153- expiry_time : linkinfo
154- . 2
150+ hits : hits. expect ( "Error getting hit count for existing shortlink." ) ,
151+ expiry_time : expiry_time
155152 . expect ( "Error getting expiry time for existing shortlink." ) ,
156153 } ;
157154 HttpResponse :: Ok ( ) . json ( body)
0 commit comments