delete.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. from .tool.func import *
  2. def delete_2(conn, name, app_var):
  3. curs = conn.cursor()
  4. ip = ip_check()
  5. if acl_check(name) == 1:
  6. return re_error('/ban')
  7. if flask.request.method == 'POST':
  8. if captcha_post(flask.request.form.get('g-recaptcha-response', '')) == 1:
  9. return re_error('/error/13')
  10. else:
  11. captcha_post('', 0)
  12. curs.execute("select data from data where title = ?", [name])
  13. data = curs.fetchall()
  14. if data:
  15. today = get_time()
  16. leng = '-' + str(len(data[0][0]))
  17. history_plus(
  18. name,
  19. '',
  20. today,
  21. ip,
  22. flask.request.form.get('send', '') + ' (delete)',
  23. leng
  24. )
  25. curs.execute("select title, link from back where title = ? and not type = 'cat' and not type = 'no'", [name])
  26. for data in curs.fetchall():
  27. curs.execute("insert into back (title, link, type) values (?, ?, 'no')", [data[0], data[1]])
  28. curs.execute("delete from back where link = ?", [name])
  29. curs.execute("delete from data where title = ?", [name])
  30. conn.commit()
  31. file_check = re.search('^file:(.+)\.(.+)$', name)
  32. if file_check:
  33. file_check = file_check.groups()
  34. os.remove(os.path.join(
  35. app_var['path_data_image'],
  36. hashlib.sha224(bytes(file_check[0], 'utf-8')).hexdigest() + '.' + file_check[1]
  37. ))
  38. return redirect('/w/' + url_pas(name))
  39. else:
  40. curs.execute("select title from data where title = ?", [name])
  41. if not curs.fetchall():
  42. return redirect('/w/' + url_pas(name))
  43. return easy_minify(flask.render_template(skin_check(),
  44. imp = [name, wiki_set(), custom(), other2([' (' + load_lang('delete') + ')', 0])],
  45. data = '''
  46. <form method="post">
  47. ''' + ip_warring() + '''
  48. <input placeholder="''' + load_lang('why') + '''" name="send" type="text">
  49. <hr class=\"main_hr\">
  50. ''' + captcha_get() + '''
  51. <button type="submit">''' + load_lang('delete') + '''</button>
  52. </form>
  53. ''',
  54. menu = [['w/' + url_pas(name), load_lang('return')]]
  55. ))