Skip to content

Commit

Permalink
feat: 支持发送照片和文件
Browse files Browse the repository at this point in the history
  • Loading branch information
soulsands committed Apr 25, 2023
1 parent 40415fa commit c705955
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 34 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ This shortcut allows you to:
- Quote clipboard content
- Quote clipboard content (clear after success)
- Input directly
- Support sending photos
- Support sending copied files
- Support for configuring fixed titles; fixed titles are used directly after configuration.
- Support for configuring optional titles; select "custom" to manually enter the title.
- Multiple default labels can be set; notes sent will be accompanied by default labels after being set.
Expand Down Expand Up @@ -57,11 +59,14 @@ To create a custom request handler file, please use the [handler](./handler.js).
3. Add a tag `#customRequestHandler={any_string}`.
4. Copy the code from the [handler](./handler.js) file into the note.

This creates an API that can be used to create notes. The request path to fill in the shortcut is `{your server}/custom/{the any_string setted early}`.
This creates an API that can be used to create notes. The request path to fill in the shortcut is `{your web server path}/custom/{the any_string setted early}`.

### Apple device

1. Open [this link](https://www.icloud.com/shortcuts/a7b7a88e67024d00a3b1d2e43306898b) on your mobile device to get the shortcut.
1. Open links on your mobile device to get the shortcut.
1. [text note](https://www.icloud.com/shortcuts/a7b7a88e67024d00a3b1d2e43306898b)
2. [file note](https://www.icloud.com/shortcuts/338e4922664c4d9cb3e60c78a782ff10)

2. Follow the instructions to install and configure the shortcut.
3. If prompted for permissions, grant them.

Expand Down
12 changes: 11 additions & 1 deletion README.zh_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ ios 15.5 可使用,其他设备没测试,ios 13 也许可用,期待反馈
- 引用剪贴板内容
- 引用剪贴板内容(成功后清除)
- 直接输入
- 支持发送照片
- 支持复制后发送文件
- 支持配置固定标题,配置后将直接使用固定标题
- 支持配置可选标题,选择`自定义`后可手动输入标题
- 可设置多个默认标签,设置后将发送笔记将附带默认标签
Expand Down Expand Up @@ -61,7 +63,11 @@ const htmlSanitizer = require("../services/html_sanitizer");

### 苹果设备

1. 用手机打开[链接](https://www.icloud.com/shortcuts/61b090d648ab44e9bba5de51ed9a9390)获取快捷指令
1. 用手机打开链接获取快捷指令。

1. [文字笔记](https://www.icloud.com/shortcuts/61b090d648ab44e9bba5de51ed9a9390)
2. [文件笔记](https://www.icloud.com/shortcuts/338e4922664c4d9cb3e60c78a782ff10)

2. 跟随指南操作。
3. 如果启用权限请允许。

Expand All @@ -82,6 +88,10 @@ const htmlSanitizer = require("../services/html_sanitizer");

使用系统分享时,可以找到快捷指令,并将其添加到收藏夹中。这样,你可以在编辑操作中将其置顶,以便更方便地访问。



虽然可以发照片和文件,但是不建议发太多,不然数据库很大。

## 快捷指令编写建议

快捷指令的编写非常不方便,拖动起来有 bug,并且容易误触删掉某个节点。
Expand Down
113 changes: 82 additions & 31 deletions handler.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const {req, res} = api;
let {title, content, labelString} = req.body;

if (req.method == "POST") {
// try to create under a note with label - messageInbox, you can rename it .
let messageInbox = api.getNoteWithLabel("messageInbox");
Expand All @@ -9,38 +7,91 @@ if (req.method == "POST") {
messageInbox = api.getDayNote(api.dayjs().format("YYYY-MM-DD"));
}

if (!title) {
title = "from ios shortcut";
}
// text note
let {content} = req.body;
if (content) {
let {title, labelString = ""} = req.body;
if (!title) {
title = "from ios shor tcut";
}

if (!content) {
content = '';
} else {
// normalize \n from message
content = content.split('\n').reduce((final, block) => {return final += `<p>${block}</p>`;}, '');
}
if (!content) {
content = "";
} else {
// normalize \n from message
content = content.split("\n").reduce((final, block) => {
return (final += `<p>${block}</p>`);
}, "");
}

const {note} = api.createNewNote({
parentNoteId: messageInbox.noteId,
title,
content,
type: "text"
});
const labels = labelString.replace(/\n/g, '').split("#");
const trimedLabels = labels.map(label => label.trim()).filter(label => label);
if (trimedLabels.length) {
trimedLabels.forEach((label) => {
const [name, value] = label.split(' ');

if (value) {
note.setLabel(name, value);
} else {
note.setLabel(name);
}
const {note} = api.createNewNote({
parentNoteId: messageInbox.noteId,
title,
content,
type: "text",
});

const labels = labelString.replace(/\n/g, "").split("#");
const trimedLabels = labels
.map((label) => label.trim())
.filter((label) => label);

if (trimedLabels.length) {
trimedLabels.forEach((label) => {
const [name, value] = label.split(" ");

if (value) {
note.setLabel(name, value);
} else {
note.setLabel(name);
}
});
} else {
note.setLabel("from ios shortcut");
}

res.status(200).json({code: 200, msg: "success", params: req.body, result: note.getPojo()});
// files
} else {
note.setLabel("from ios shortcut");
}
const multer = require("multer");
const importRoute = require("../routes/api/import");
const uploadMiddleware = multer().single("upload");

uploadMiddleware(req, res, () => {

req.body.taskId = api.randomString(10);;
req.body.last = "true";
req.params.parentNoteId = messageInbox.noteId;

const options = {
safeImport: "true", // set to "false" (with quotes) if you don't need it, same below.
shrinkImages: "true",
textImportedAsText: "true",
codeImportedAsCode: "true",
explodeArchives: "true",
replaceUnderscoresWithSpaces: "true",
};

res.status(200).json({code: 200, msg: "success", params: req.body});
req.body = {...req.body, ...options};

importRoute
.importToBranch(req)
.then((resualt) => {
res.status(200).json({
code: 200,
msg: "success",
params: req.body,
result: resualt,
});
})
.catch((err) => {
res.status(500).json({
code: 500,
msg: "fail",
params: req.body,
error: err,
});
});
});
}
}

0 comments on commit c705955

Please sign in to comment.