@@ -200,6 +200,37 @@ def post(self, p=''):
200200 res = make_response (json .JSONEncoder ().encode (info ), 401 )
201201 res .headers .add ('Content-type' , 'application/json' )
202202 return res
203+
204+ def delete (self , p = '' ):
205+ if request .cookies .get ('auth_cookie' ) == key :
206+ path = os .path .join (root , p )
207+ dir_path = os .path .dirname (path )
208+ Path (dir_path ).mkdir (parents = True , exist_ok = True )
209+
210+ info = {}
211+ if os .path .isdir (dir_path ):
212+ try :
213+ filename = secure_filename (os .path .basename (path ))
214+ os .remove (os .path .join (dir_path , filename ))
215+ os .rmdir (dir_path )
216+ except Exception as e :
217+ info ['status' ] = 'error'
218+ info ['msg' ] = str (e )
219+ else :
220+ info ['status' ] = 'success'
221+ info ['msg' ] = 'File Deleted'
222+ else :
223+ info ['status' ] = 'error'
224+ info ['msg' ] = 'Invalid Operation'
225+ res = make_response (json .JSONEncoder ().encode (info ), 204 )
226+ res .headers .add ('Content-type' , 'application/json' )
227+ else :
228+ info = {}
229+ info ['status' ] = 'error'
230+ info ['msg' ] = 'Authentication failed'
231+ res = make_response (json .JSONEncoder ().encode (info ), 401 )
232+ res .headers .add ('Content-type' , 'application/json' )
233+ return res
203234
204235path_view = PathView .as_view ('path_view' )
205236app .add_url_rule ('/' , view_func = path_view )
0 commit comments