def DELETE(self): ID = request.args.get("id") dir_path = os.path.join(STOREPATH, str(ID)) if not os.path.isdir(dir_path): return "-1" shutil.rmtree(dir_path) BD = BlogData(STOREPATH) return BD.delete(str(ID))
def PUT(self): Id = request.args.get("id") data = json.loads(request.data).get("tex","") dir_path = os.path.join(STOREPATH, str(Id)) if not os.path.isdir(dir_path): logging.info("%s: is not exit"%dir_path) return "-1" #路径不存在 file_path = os.path.join(dir_path, "index.md") with open(file_path,"w") as fp: fp.write(data) (infos, tex) = get_info(file_path) BD = BlogData(STOREPATH) return BD.update(str(Id), infos, tex)
def post(self): form = request.form title = form.get("title") tags = form.get("tags") if tags: tags = tags.split(",") else: tags = [ ] cls = form.get("cls","undefine") context = form.get("context") publish = form.get("publish", False) bd = BlogData(STOREPATH) bd.add(title, context, tags, cls, publish) return "sucess!"
def POST(self): form = json.loads(request.data) tex = form.get("tex", " ") Id = setid() dir_path = os.path.join(STOREPATH,str(Id)) if os.path.isdir(dir_path): return "-1" #路径重复 os.mkdir(dir_path) file_path = os.path.join(dir_path, "index.md") with open(file_path, "w") as fp: fp.write(tex) (infos, tex) = get_info(file_path) BD = BlogData(STOREPATH) return BD.add(str(Id), infos, tex)