Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

feat: default editor supports pasting or dragging pictures to upload #825

Merged
merged 9 commits into from
Feb 1, 2023

Conversation

ruibaby
Copy link
Member

@ruibaby ruibaby commented Jan 16, 2023

What type of PR is this?

/kind feature

What this PR does / why we need it:

添加复制或者拖拽图片到编辑器上传的支持。

Which issue(s) this PR fixes:

Fixes halo-dev/halo#3109
Fixes halo-dev/halo#2946

Screenshots:

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Console 端的默认编辑器支持拖拽或者粘贴图片上传

@f2c-ci-robot f2c-ci-robot bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. labels Jan 16, 2023
@vercel
Copy link

vercel bot commented Jan 16, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
ui ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Jan 31, 2023 at 7:10AM (UTC)

@ruibaby ruibaby changed the title feat: default editor supports pasting or dragging pictures to upload WIP: feat: default editor supports pasting or dragging pictures to upload Jan 16, 2023
@f2c-ci-robot f2c-ci-robot bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 16, 2023
@ruibaby ruibaby changed the title WIP: feat: default editor supports pasting or dragging pictures to upload feat: default editor supports pasting or dragging pictures to upload Jan 31, 2023
@f2c-ci-robot f2c-ci-robot bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 31, 2023
Copy link
Member

@JohnNiang JohnNiang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有办法重命名从剪贴板粘贴的图片名称(image.png)么?否则第二次粘贴的时候会出现“附件已存在”错误。

@ruibaby
Copy link
Member Author

ruibaby commented Feb 1, 2023

有办法重命名从剪贴板粘贴的图片名称(image.png)么?否则第二次粘贴的时候会出现“附件已存在”错误。

恐怕不是太好判断剪贴板的文件是不是从电脑上复制的,目前仅发现截图之后会有这样的情况,如果单纯根据文件名(image.png)来判断似乎也不合理,因为每一个浏览器都不一样,还可能受到浏览器语言的影响,参考:halo-dev/halo#2945 (comment)

我认为可以像 1.x 一样,在后端判断是否有重复文件,然后重命名。

@ruibaby
Copy link
Member Author

ruibaby commented Feb 1, 2023

image

GitHub 的上传也不是在前端重命名之后再上传的。

Copy link
Member

@JohnNiang JohnNiang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

文件名重复的问题暂时和当前 PR 无关。

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Feb 1, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JohnNiang

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@f2c-ci-robot f2c-ci-robot bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 1, 2023
Copy link
Member

@guqing guqing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@f2c-ci-robot f2c-ci-robot bot added the lgtm Indicates that a PR is ready to be merged. label Feb 1, 2023
@f2c-ci-robot f2c-ci-robot bot merged commit 8f6d543 into halo-dev:main Feb 1, 2023
@ruibaby ruibaby deleted the feat/paste-to-upload-image branch February 1, 2023 02:51
@zhangy2233
Copy link

zhangy2233 commented Feb 1, 2023

这样上传的文件, 如果文章删除, 图片依然在附件里, 如果文章很多, 附件很多, 如果不手动删除附件, 那一直存在系统里, upload文件里

@JohnNiang
Copy link
Member

这样上传的文件, 如果文章删除, 图片依然在附件里, 如果文章很多, 附件很多, 如果不手动删除附件, 那一直存在系统里, upload文件里

目前是这样的。请问有比较好的实现方式么?

@zhangy2233
Copy link

zhangy2233 commented Feb 1, 2023

这样上传的文件, 如果文章删除, 图片依然在附件里, 如果文章很多, 附件很多, 如果不手动删除附件, 那一直存在系统里, upload文件里

目前是这样的。请问有比较好的实现方式么?

不知道在2.1存不存在这个问题, 2.1是没保存在附件库里, 以前做过类似的, 图片上传的时候给图片重命名, 文件名和文章关联之后, 删除文章也顺便把文件名删除(不过这样
不过这样还存在问题, 就是一个文章我编辑的时候, 添加了一个图片(这时已经上传了), 但是后面我觉得这个图片不好, 我删除了文中的这个图片, 替换新的图片之后, 附件库会存在 旧图片和新图片

还有一个问题, 2.1->2.2 之后, 文章中的图片无法显示了

想到以前做的废弃的博客网站, 对于几种情况, 图片以及附件处理的方式
前置: 用户的图片按照附件的形式上传到服务器, 所以文章中的附件名,服务器默认认为已经在服务器, 如果文章 发布成功/附件被使用, 会有一个字段表示这种状态, 发布文章时会检查文本中的文字, 做了一个简单的自动机来解析出现的附件文件名, 根据文件名设置 一个字段 表示如下情况:
status1. 该附件被自动上传 并没有使用
status2. 该附件被自动上传 已经使用
status3. 该附件被用户主动上传 已经使用
status4. 该附件被用户主动上传 没有使用

如果出现以下的情况:

  1. 用户编辑文章 在文章中插入了图片A, 随后关闭浏览器
  2. 用户编辑文章 在文章中插入了图片A, 随后点击 "取消"
  3. 用户编辑文章 插入图片A, 然后不满意图片A, 删除图片A 使用图片B
    这个附件一直在云服务器上, 文章也没有发布出来, 等于失联了, 我当时是有一个定时任务每天会查询 上面的然后删除 status1

@ruibaby ruibaby modified the milestones: 2.2.x, 2.2.0 Feb 10, 2023
JohnNiang pushed a commit to JohnNiang/halo that referenced this pull request Mar 2, 2023
…alo-dev/console#825)

#### What type of PR is this?

/kind feature

#### What this PR does / why we need it:

添加复制或者拖拽图片到编辑器上传的支持。

#### Which issue(s) this PR fixes:

Fixes halo-dev#3109
Fixes halo-dev#2946

#### Screenshots:


#### Special notes for your reviewer:

#### Does this PR introduce a user-facing change?


```release-note
Console 端的默认编辑器支持拖拽或者粘贴图片上传
```
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

默认编辑器支持拖拽/粘贴图片之后上传到附件库 富文本图片粘贴与存储打通
4 participants