diff --git a/README.md b/README.md index 8d5ff9f8..51f3373e 100644 --- a/README.md +++ b/README.md @@ -138,10 +138,8 @@ to [Latest Adaptation](https://terwergreen.feishu.cn/share/base/view/shrcnWT2IGI ## Version Preview -### 1.21.5-preview – As of Q1 2024 +### 1.26.2-preview – As of Q1 2025 -- Expansion of telegra.ph support for image uploads - - Reference: https://www.npmjs.com/package/telegraph-uploader - Rectification of scenarios entailing repetitive image uploads across select platforms - Resolution of formatting discrepancies within WeChat public accounts - #990 Rectification of irregular display issues while posting to Jian Shu @@ -150,27 +148,27 @@ to [Latest Adaptation](https://terwergreen.feishu.cn/share/base/view/shrcnWT2IGI - #948 #905 Corrections addressing halo platform-related concerns - Addressing vuepress2 related issues -### 1.21.6-preview – As of Q1 2024 +### 1.26.3-preview – As of Q1 2025 - Inclusion of support for BiliBili and Xiaohongshu platforms -### 1.22.0-preview – As of Q2 2024 +### 1.27.0-preview – As of Q2 2025 - Embracing compatibility for Evernote and Antora (including GitHub and GitLab) -### 1.23.0-preview – As of Q2 2024 +### 1.28.0-preview – As of Q2 2025 - Enabling support for Docsify (inclusive of GitHub and GitLab) and Douban -### 1.24.0-preview – As of Q2 2024 +### 1.29.0-preview – As of Q2 2025 - Integration with flowus platform -### 1.25.0-preview – As of Q2 2024 +### 1.30.0-preview – As of Q2 2025 - Extending support to Xlog, mdnice, and zola platforms -### 1.26.0-preview – As of Q3 2024 +### 1.31.0-preview – As of Q3 2025 - Collaborative interactions with #956 and OceanPress diff --git a/README_zh_CN.md b/README_zh_CN.md index 67ebb7bd..5f0678af 100644 --- a/README_zh_CN.md +++ b/README_zh_CN.md @@ -127,10 +127,8 @@ ## 版本预告 -### 1.21.5-preview - 截止到 2024 年 Q1 +### 1.26.2-preview - 截止到 2025 年 Q1 -- telegra.ph 支持上传图片 - - 参考 https://www.npmjs.com/package/telegraph-uploader - 解决部分平台在某些场景下重复上传图片的问题 - 修复微信公众号排版问题 - #990 修复发布到简书时部分格式显示不正常的问题 @@ -139,27 +137,27 @@ - #948 #905 halo 平台相关问题修复 - vuepress2 相关问题 -### 1.21.6-preview - 截止到 2024 年 Q1 +### 1.26.3-preview - 截止到 2025 年 Q1 - 支持 B 站、小红书 -### 1.22.0-preview - 截止到 2024 年 Q2 +### 1.27.0-preview - 截止到 2025 年 Q2 - 支持 Evernote、Antora(包括 GitHub 和 gitlab) -### 1.23.0-preview - 截止到 2024 年 Q2 +### 1.28.0-preview - 截止到 2025 年 Q2 - 支持 Docsify(包括 GitHub 和 gitlab)、Douban -### 1.24.0-preview - 截止到 2024 年 Q2 +### 1.29.0-preview - 截止到 2025 年 Q2 - 支持 flowus -### 1.25.0-preview - 截止到 2024 年 Q2 +### 1.30.0-preview - 截止到 2025 年 Q2 - 支持 Xlog、mdnice、zola -### 1.26.0-preview - 截止到 2024 年 Q3 +### 1.31.0-preview - 截止到 2025 年 Q3 - #956 和 OceanPress 联动 diff --git a/src/adaptors/api/telegraph/telegraphApiAdaptor.ts b/src/adaptors/api/telegraph/telegraphApiAdaptor.ts index a4c4908c..b404c6ef 100644 --- a/src/adaptors/api/telegraph/telegraphApiAdaptor.ts +++ b/src/adaptors/api/telegraph/telegraphApiAdaptor.ts @@ -24,7 +24,7 @@ */ import { BaseBlogApi } from "~/src/adaptors/api/base/baseBlogApi.ts" -import { Post, UserBlog } from "zhi-blog-api" +import { Attachment, MediaObject, Post, UserBlog } from "zhi-blog-api" import { TelegraphConfig, TelegraphPostType } from "~/src/adaptors/api/telegraph/telegraphConfig.ts" import { JsonUtil, StrUtil } from "zhi-common" import CookieUtils from "~/src/utils/cookieUtils.ts" @@ -258,11 +258,54 @@ class TelegraphApiAdaptor extends BaseBlogApi { return commonPost } + // 已失效,上传功能无法实现 + // public async newMediaObject(mediaObject: MediaObject, customHandler?: any): Promise { + // const tgCfg = this.cfg as TelegraphConfig + // + // let xCorsHeaders: Record = {} + // + // // x-cors-headers + // let requestCookie: string + // const uuidCookie = `${this.TPH_UUID_KEY}=${tgCfg.password}` + // if (tgCfg.postType == TelegraphPostType.ANONYMOUS) { + // if (StrUtil.isEmptyString(tgCfg.password)) { + // throw new Error(`Cookie ${this.TPH_UUID_KEY} 获取失败,无法上传附件`) + // } + // requestCookie = uuidCookie + // this.logger.warn("当前为匿名发布") + // } else { + // if (StrUtil.isEmptyString(tgCfg.password) || StrUtil.isEmptyString(tgCfg.accessToken)) { + // throw new Error(`Cookie ${this.TPH_UUID_KEY},${this.TPH_TOKEN_KEY} 获取失败,无法上传附件`) + // } + // const tokenCookie = `${this.TPH_TOKEN_KEY}=${tgCfg.accessToken}` + // requestCookie = [uuidCookie, tokenCookie].join(";") + // } + // xCorsHeaders["Cookie"] = requestCookie ?? "" + // xCorsHeaders["origin"] = "https://telegra.ph" + // xCorsHeaders["referer"] = "https://telegra.ph/" + // + // const headers = { + // // for cors proxy + // // siyuan proxy should ignore this header + // "x-cors-headers": JSON.stringify(xCorsHeaders), + // } + // for (const [xkey, xvalue] of Object.entries(xCorsHeaders)) { + // headers[xkey] = xvalue + // } + // + // const bits = mediaObject.bits + // const formData = new FormData() + // const blob = new Blob([bits], { type: mediaObject.type }) + // formData.append("file", blob, mediaObject.name) + // const res = await this.telegraphFormFetch("/upload", formData) + // this.logger.debug("telegraph upload success, res =>", res) + // } + public async getPreviewUrl(postid: string): Promise { const postMeta = JsonUtil.safeParse(postid, {}) const purl = this.cfg.previewUrl ?? "" const postUrl = purl.replace("[postid]", postMeta?.path ?? "") - const useProxyPreview = true + const useProxyPreview = false if (useProxyPreview && !StrUtil.isEmptyString(this.cfg.corsAnywhereUrl)) { const proxyHome = StrUtil.pathJoin(this.cfg.corsAnywhereUrl, this.cfg.home ?? "") return StrUtil.pathJoin(`${proxyHome}`, postUrl) diff --git a/src/adaptors/api/telegraph/useTelegraphApi.ts b/src/adaptors/api/telegraph/useTelegraphApi.ts index fdb01651..43c7bbee 100644 --- a/src/adaptors/api/telegraph/useTelegraphApi.ts +++ b/src/adaptors/api/telegraph/useTelegraphApi.ts @@ -71,6 +71,7 @@ const useTelegraphApi = async (key: string, newCfg?: TelegraphConfig) => { cfg.postType = cfg.postType ?? TelegraphPostType.ANONYMOUS // picbed service cfg.picgoPicbedSupported = true + // 已失效。无法实现 cfg.bundledPicbedSupported = false const blogApi = new TelegraphApiAdaptor(appInstance, cfg) diff --git a/src/platforms/pre.ts b/src/platforms/pre.ts index 9e76dd87..3a6d9a46 100644 --- a/src/platforms/pre.ts +++ b/src/platforms/pre.ts @@ -259,6 +259,7 @@ export const pre = { authMode: AuthMode.WEBSITE, authUrl: "https://www.zhihu.com/signin", domain: "zhihu.com", + cookieLimit: true, isEnabled: false, }, { diff --git a/testdata/telegra-ph/upload.py b/testdata/telegra-ph/upload.py new file mode 100644 index 00000000..3218a4d0 --- /dev/null +++ b/testdata/telegra-ph/upload.py @@ -0,0 +1,17 @@ +import requests +import sys + +# 已失效。无法实现 +# python upload.py /Volumes/workspace/pictures/photo.jpg +if __name__ == '__main__': + if len(sys.argv) < 2: + print("You must specify a file name.") + sys.exit(-1) + filePath = sys.argv[1] + with open(filePath, 'rb') as f: + # Upload File + json_data = requests.post('https://telegra.ph/upload', files={'file': ('file', f, 'image/jpeg')}).json() # image/gif, image/jpeg, image/jpg, image/png, video/mp4 + print(f"upload res=>{json_data}") + # get file URL + filename = "https://telegra.ph" + json_data[0]['src'] + print(filename) \ No newline at end of file