diff --git a/blog.py b/blog.py index b02232aa..3a7752b4 100644 --- a/blog.py +++ b/blog.py @@ -609,7 +609,9 @@ def htmlEditBlog(mediaInstance: bool,translate: {}, \ editBlogForm+= \ '<form enctype="multipart/form-data" method="POST" accept-charset="UTF-8" action="'+ \ - pathBase+'?'+endpoint+'?page='+str(pageNumber)+'">' + pathBase+'?'+endpoint+'">' + editBlogForm+=' <input type="hidden" name="postUrl" value="'+postUrl+'">' + editBlogForm+=' <input type="hidden" name="pageNumber" value="'+str(pageNumber)+'">' editBlogForm+=' <div class="vertical-center">' editBlogForm+=' <label for="nickname"><b>'+editBlogText+'</b></label>' editBlogForm+=' <div class="container">' @@ -622,7 +624,8 @@ def htmlEditBlog(mediaInstance: bool,translate: {}, \ editBlogForm+= \ ' <a href="'+pathBase+ \ - '/searchemoji"><img loading="lazy" class="emojisearch" src="/emoji/1F601.png" title="'+ \ + '/searchemoji"><img loading="lazy" '+ \ + 'class="emojisearch" src="/emoji/1F601.png" title="'+ \ translate['Search for emoji']+'" alt="'+ \ translate['Search for emoji']+'"/></a>' editBlogForm+=' </div>' @@ -645,10 +648,13 @@ def htmlEditBlog(mediaInstance: bool,translate: {}, \ editBlogForm+= \ ' <input type="text" name="subject" value="'+titleStr+'">' editBlogForm+='' - editBlogForm+=' <br><label class="labels">'+placeholderMessage+'</label>' + editBlogForm+= \ + ' <br><label class="labels">'+ \ + placeholderMessage+'</label>' messageBoxHeight=800 - contentStr=postJsonObject['object']['content'].replace('<p>','').replace('</p>','') + contentStr= \ + postJsonObject['object']['content'].replace('<p>','').replace('</p>','') editBlogForm+= \ ' <textarea id="message" name="message" style="height:'+ \ diff --git a/daemon.py b/daemon.py index 9ee93b87..3c380346 100644 --- a/daemon.py +++ b/daemon.py @@ -3896,8 +3896,7 @@ class PubServer(BaseHTTPRequestHandler): return -1 elif postType=='newblog': messageJson= \ - createBlogPost(self.server.baseDir, \ - nickname, \ + createBlogPost(self.server.baseDir,nickname, \ self.server.domain,self.server.port, \ self.server.httpPrefix, \ fields['message'],False,False,False, \ @@ -5362,6 +5361,75 @@ class PubServer(BaseHTTPRequestHandler): self._benchmarkPOSTtimings(POSTstartTime,POSTtimings,13) + # edit blog post + if authorized and self.path.endswith('/tlblogs?editblogpost'): + pageNumber=1 + + length = int(self.headers['Content-length']) + if length>self.server.maxPostLength: + print('POST size too large') + self.send_response(429) + self.end_headers() + return + + optionsConfirmParams= \ + self.rfile.read(length).decode('utf-8').replace('%40','@').replace('%3A',':').replace('%23','#').replace('%2F','/').replace('%3F','') + postUrl=None + if 'postUrl=' in optionsConfirmParams: + postUrl=optionsConfirmParams.split('postUrl=')[1] + if '&' in postUrl: + postUrl=postUrl.split('&')[0] + originPathStr= \ + self.server.httpPrefix+'://'+self.server.domainFull+ \ + self.path.split('?')[0] + if postUrl: + titleStr='' + if 'subject=' in optionsConfirmParams: + titleStr=optionsConfirmParams.split('subject=')[1] + if '&' in titleStr: + titleStr=titleStr.split('&')[0] + titleStr=titleStr.replace('%26','&') + contentStr='' + if 'message=' in optionsConfirmParams: + contentStr=optionsConfirmParams.split('message=')[1] + if '&' in contentStr: + contentStr=contentStr.split('&')[0] + contentStr=contentStr.replace('%26','&') + #editNickname=getNicknameFromActor(originPathStr) + # page number to return to + if 'pageNumber=' in optionsConfirmParams: + pageNumberStr=optionsConfirmParams.split('pageNumber=')[1] + if '&' in pageNumberStr: + pageNumberStr=pageNumberStr.split('&')[0] + if pageNumberStr.isdigit(): + pageNumber=int(pageNumberStr) + nickname= \ + getNicknameFromActor(originPathStr) + postFilename= \ + locatePost(self.server.baseDir, \ + nickname,self.server.domain, \ + postUrl) + if postFilename and titleStr and contentStr: + postJsonObject=loadJson(postFilename) + if postJsonObject: + # remove any previous cached html + cacheFilename= \ + self.server.baseDir+'/postcache/' + \ + postUrl.replace('/','#')+'.html' + if os.path.isfile(cacheFilename): + try: + os.remove(cacheFilename) + except: + pass + # save the new blog post + postJsonObject['object']['summary']=titleStr + postJsonObject['object']['content']=contentStr + saveJson(postJsonObject,postFilename) + self.server.POSTbusy=False + self._redirect_headers(originPathStr+ \ + '?page='+str(pageNumber),cookie) + return + # an option was chosen from person options screen # view/follow/block/report if authorized and self.path.endswith('/personoptions'):