mirror of
https://github.com/doocs/md.git
synced 2024-11-28 13:36:32 +08:00
feat: update file api methods
This commit is contained in:
parent
73b0f2ca5a
commit
6645eb3cde
12
README.md
12
README.md
@ -45,13 +45,13 @@ Markdown 文档自动即时渲染为微信图文,让你不再为微信文章
|
|||||||
## 目前支持哪些图床
|
## 目前支持哪些图床
|
||||||
|
|
||||||
| # | 图床 | 使用时是否需要配置 | 备注 |
|
| # | 图床 | 使用时是否需要配置 | 备注 |
|
||||||
| --- | ----------- | ------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------- |
|
| --- | ----------------------------------------------- | ---------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
|
||||||
| 1 | 默认 | 否 | - |
|
| 1 | 默认 | 否 | - |
|
||||||
| 2 | Gitee | 配置 `Repo`、`Token` 参数 | 图片超过 1MB 无法正常展示 |
|
| 2 | [Gitee](https://gitee.com) | 配置 `Repo`、`Token` 参数 | 图片超过 1MB 无法正常展示 |
|
||||||
| 3 | GitHub | 配置 `Repo`、`Token` 参数 | [如何获取 GitHub token?](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) |
|
| 3 | [GitHub](https://github.com) | 配置 `Repo`、`Token` 参数 | [如何获取 GitHub token?](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) |
|
||||||
| 4 | 阿里云 OSS | 配置 `AccessKey ID`、`AccessKey Secret`、`Bucket`、`Region` 等参数 | [如何使用阿里云 OSS?](https://help.aliyun.com/document_detail/31883.html) |
|
| 4 | [阿里云](https://www.aliyun.com/product/oss) | 配置 `AccessKey ID`、`AccessKey Secret`、`Bucket`、`Region` 参数 | [如何使用阿里云 OSS?](https://help.aliyun.com/document_detail/31883.html) |
|
||||||
| 5 | 腾讯云 COS | 配置 `SecretId`、`SecretKey`、`Bucket`、`Region` 等参数 | [如何使用腾讯云 COS?](https://cloud.tencent.com/document/product/436/38484) |
|
| 5 | [腾讯云](https://cloud.tencent.com/act/pro/cos) | 配置 `SecretId`、`SecretKey`、`Bucket`、`Region` 参数 | [如何使用腾讯云 COS?](https://cloud.tencent.com/document/product/436/38484) |
|
||||||
| 6 | 七牛云 Kodo | 配置 `AccessKey`、`SecretKey`、`Bucket`、`Domain`、`Region` 等参数 | [如何使用七牛云 Kodo?](https://developer.qiniu.com/kodo) |
|
| 6 | [七牛云](https://www.qiniu.com/products/kodo) | 配置 `AccessKey`、`SecretKey`、`Bucket`、`Domain`、`Region` 参数 | [如何使用七牛云 Kodo?](https://developer.qiniu.com/kodo) |
|
||||||
|
|
||||||
![select-and-change-color-theme](./public/assets/images/select-and-change-color-theme.gif)
|
![select-and-change-color-theme](./public/assets/images/select-and-change-color-theme.gif)
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ function fileUpload(content, file) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getGitHubCommonConfig(username, repo, branch, token) {
|
function getDir() {
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
const dir =
|
const dir =
|
||||||
date.getFullYear() +
|
date.getFullYear() +
|
||||||
@ -49,6 +49,17 @@ function getGitHubCommonConfig(username, repo, branch, token) {
|
|||||||
(date.getMonth() + 1).toString().padStart(2, "0") +
|
(date.getMonth() + 1).toString().padStart(2, "0") +
|
||||||
"/" +
|
"/" +
|
||||||
date.getDate().toString().padStart(2, "0");
|
date.getDate().toString().padStart(2, "0");
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDateFilename(filename) {
|
||||||
|
const dateFilename =
|
||||||
|
new Date().getTime() + "-" + uuidv4() + "." + filename.split(".")[1];
|
||||||
|
return dateFilename;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getGitHubCommonConfig(username, repo, branch, token) {
|
||||||
|
const dir = getDir();
|
||||||
return {
|
return {
|
||||||
method: "put",
|
method: "put",
|
||||||
headers: {
|
headers: {
|
||||||
@ -99,8 +110,7 @@ function getQiniuToken(accessKey, secretKey, putPolicy) {
|
|||||||
async function ghFileUpload(content, filename) {
|
async function ghFileUpload(content, filename) {
|
||||||
const isDefault = localStorage.getItem("imgHost") !== "github";
|
const isDefault = localStorage.getItem("imgHost") !== "github";
|
||||||
const config = isDefault ? getDefaultConfig() : getGitHubConfig();
|
const config = isDefault ? getDefaultConfig() : getGitHubConfig();
|
||||||
const dateFilename =
|
const dateFilename = getDateFilename(filename);
|
||||||
new Date().getTime() + "-" + uuidv4() + "." + filename.split(".")[1];
|
|
||||||
const res = await fetch({
|
const res = await fetch({
|
||||||
url: config.url + dateFilename,
|
url: config.url + dateFilename,
|
||||||
method: config.method,
|
method: config.method,
|
||||||
@ -127,15 +137,8 @@ async function giteeUpload(content, filename) {
|
|||||||
.split("/");
|
.split("/");
|
||||||
const username = repoUrl[0];
|
const username = repoUrl[0];
|
||||||
const repo = repoUrl[1];
|
const repo = repoUrl[1];
|
||||||
const date = new Date();
|
const dir = getDir();
|
||||||
const dir =
|
const dateFilename = getDateFilename(filename);
|
||||||
date.getFullYear() +
|
|
||||||
"/" +
|
|
||||||
(date.getMonth() + 1).toString().padStart(2, "0") +
|
|
||||||
"/" +
|
|
||||||
date.getDate().toString().padStart(2, "0");
|
|
||||||
const dateFilename =
|
|
||||||
new Date().getTime() + "-" + uuidv4() + "." + filename.split(".")[1];
|
|
||||||
const res = await fetch({
|
const res = await fetch({
|
||||||
url: `https://gitee.com/api/v5/repos/${username}/${repo}/contents/${dir}/${dateFilename}`,
|
url: `https://gitee.com/api/v5/repos/${username}/${repo}/contents/${dir}/${dateFilename}`,
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@ -150,8 +153,7 @@ async function giteeUpload(content, filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function aliOSSFileUpload(content, filename) {
|
async function aliOSSFileUpload(content, filename) {
|
||||||
const dateFilename =
|
const dateFilename = getDateFilename(filename);
|
||||||
new Date().getTime() + "-" + uuidv4() + "." + filename.split(".")[1];
|
|
||||||
const aliOSSConfig = JSON.parse(localStorage.getItem("aliOSSConfig"));
|
const aliOSSConfig = JSON.parse(localStorage.getItem("aliOSSConfig"));
|
||||||
const buffer = Buffer(content, "base64");
|
const buffer = Buffer(content, "base64");
|
||||||
try {
|
try {
|
||||||
@ -174,8 +176,7 @@ async function aliOSSFileUpload(content, filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function txCOSFileUpload(file) {
|
async function txCOSFileUpload(file) {
|
||||||
const dateFilename =
|
const dateFilename = getDateFilename(file.name);
|
||||||
new Date().getTime() + "-" + uuidv4() + "." + file.name.split(".")[1];
|
|
||||||
const txCOSConfig = JSON.parse(localStorage.getItem("txCOSConfig"));
|
const txCOSConfig = JSON.parse(localStorage.getItem("txCOSConfig"));
|
||||||
const cos = new COS({
|
const cos = new COS({
|
||||||
SecretId: txCOSConfig.secretId,
|
SecretId: txCOSConfig.secretId,
|
||||||
@ -224,13 +225,7 @@ async function qiniuUpload(file) {
|
|||||||
putPolicy
|
putPolicy
|
||||||
);
|
);
|
||||||
const dir = qiniuConfig.path ? qiniuConfig.path + "/" : "";
|
const dir = qiniuConfig.path ? qiniuConfig.path + "/" : "";
|
||||||
const dateFilename =
|
const dateFilename = dir + getDateFilename(file.name);
|
||||||
dir +
|
|
||||||
new Date().getTime() +
|
|
||||||
"-" +
|
|
||||||
uuidv4() +
|
|
||||||
"." +
|
|
||||||
file.name.split(".")[1];
|
|
||||||
const config = {
|
const config = {
|
||||||
region: qiniuConfig.region,
|
region: qiniuConfig.region,
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user