mirror of
https://github.com/FliegendeWurst/telegram_notes_bot.git
synced 2024-12-03 15:34:06 +00:00
Set the correct mime of imported ical content
as a bonus, this commit also includes a useful button: duplicate an event into the next week
This commit is contained in:
parent
79db3f6b4f
commit
76cdb42c21
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
target
|
||||
.env
|
||||
|
2
TODO.txt
Normal file
2
TODO.txt
Normal file
@ -0,0 +1,2 @@
|
||||
- handle URL fields in ical files
|
||||
- handle escape codes in ical files
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"formatVersion": 1,
|
||||
"appVersion": "0.46.9",
|
||||
"appVersion": "0.47.2",
|
||||
"files": [
|
||||
{
|
||||
"isClone": false,
|
||||
@ -378,6 +378,30 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"isClone": false,
|
||||
"noteId": "Q7KqwQ1693Bj",
|
||||
"notePath": [
|
||||
"vP5DkrdHVvv0",
|
||||
"Q7KqwQ1693Bj"
|
||||
],
|
||||
"title": "duplicate into next week button",
|
||||
"notePosition": 81,
|
||||
"prefix": null,
|
||||
"isExpanded": 0,
|
||||
"type": "code",
|
||||
"mime": "application/javascript;env=frontend",
|
||||
"attributes": [
|
||||
{
|
||||
"type": "label",
|
||||
"name": "run",
|
||||
"value": "frontendStartup",
|
||||
"isInheritable": false,
|
||||
"position": 10
|
||||
}
|
||||
],
|
||||
"dataFileName": "duplicate into next week button.js"
|
||||
},
|
||||
{
|
||||
"isClone": false,
|
||||
"noteId": "X5pzYZriILAz",
|
||||
|
30
notes/Implementation/duplicate into next week button.js
Normal file
30
notes/Implementation/duplicate into next week button.js
Normal file
@ -0,0 +1,30 @@
|
||||
api.addButtonToToolbar({
|
||||
title: 'Duplicate into next week',
|
||||
icon: 'right-arrow-alt',
|
||||
action: async () => {
|
||||
await api.runOnBackend(async (noteId) => {
|
||||
const note = await api.getNote(noteId);
|
||||
const targetTemplate = await note.getRelation('template').value;
|
||||
const startTime = await note.getLabelValue('startTime');
|
||||
const location = await note.getLabelValue('location');
|
||||
const date = new Date(startTime);
|
||||
date.setTime(date.getTime() + (7*24*60*60*1000));
|
||||
|
||||
const todayDateStr = date.toISOString().substr(0,10);
|
||||
const todayNote = await api.getDateNote(todayDateStr);
|
||||
const newTime = todayDateStr + "T" + date.getHours().toString().padStart(2, '0') + ":" + date.getMinutes().toString().padStart(2, '0') + ":" + date.getSeconds().toString().padStart(2, '0');
|
||||
|
||||
const resp = await api.createNewNote({
|
||||
parentNoteId: todayNote.noteId,
|
||||
title: note.title,
|
||||
content: '',
|
||||
type: 'text'
|
||||
});
|
||||
await resp.note.setAttribute("relation", "template", targetTemplate);
|
||||
await resp.note.setAttribute("label", "startTime", newTime);
|
||||
if (location) {
|
||||
await resp.note.setAttribute("label", "location", location);
|
||||
}
|
||||
}, [api.getActiveTabNote().noteId]);
|
||||
}
|
||||
});
|
@ -7,6 +7,7 @@ const {req, res} = api;
|
||||
const uid = req.body["uid"];
|
||||
const name = req.body["name"];
|
||||
const summary = req.body["summary"];
|
||||
const summaryHtml = req.body["summaryHtml"];
|
||||
const location = req.body["location"];
|
||||
const fileName = req.body["fileName"];
|
||||
const fileData = req.body["fileData"];
|
||||
@ -31,8 +32,9 @@ const targetTemplate = await api.currentNote.getRelationValue('targetTemplate');
|
||||
const options = {
|
||||
"parentNoteId": dayNote.noteId,
|
||||
"title": name,
|
||||
"content": summary,
|
||||
"type": "text"
|
||||
"content": summaryHtml != "" ? summaryHtml : summary,
|
||||
"type": "text",
|
||||
"mime": summaryHtml != "" ? "text/html" : "text/plain"
|
||||
};
|
||||
const resp = await api.createNewNote(options);
|
||||
const note = resp.note;
|
||||
|
@ -35,6 +35,8 @@
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="Implementation/duplicate%20into%20next%20week%20button.js" target="detail">duplicate into next week button</a>
|
||||
</li>
|
||||
<li><a href="Implementation/event%20template.html" target="detail">event template</a>
|
||||
</li>
|
||||
<li><a href="Implementation/new_event%20handler.js" target="detail">new_event handler</a>
|
||||
|
@ -139,7 +139,8 @@ async fn process_one(update: Update, context: &mut Context) -> Result<(), Error>
|
||||
if CLIENT.get(&trilium_url("/custom/new_event")).form(&json!({
|
||||
"uid": calendar.events[0].uid,
|
||||
"name": calendar.events[0].summary,
|
||||
"summary": calendar.events[0].description_html.as_deref().unwrap_or(&calendar.events[0].description),
|
||||
"summary": calendar.events[0].description,
|
||||
"summaryHtml": calendar.events[0].description_html.as_deref().unwrap_or_default(),
|
||||
"fileName": document.file_name,
|
||||
"fileData": text,
|
||||
"location": calendar.events[0].location,
|
||||
|
Loading…
Reference in New Issue
Block a user