Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
# Conflicts:
#	package.json
#	src/services/build.js
#	src/services/notes.js
  • Loading branch information
zadam committed Jan 7, 2024
2 parents d63d42d + d6046ef commit e2cb3c0
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 9 deletions.
165 changes: 163 additions & 2 deletions src/etapi/etapi.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,116 @@ paths:
application/json; charset=utf-8:
schema:
$ref: '#/components/schemas/Error'
/attachments:
post:
description: create an attachment
operationId: postAttachment
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/CreateAttachment'
responses:
'201':
description: attachment created
content:
application/json; charset=utf-8:
schema:
$ref: '#/components/schemas/Attachment'
default:
description: unexpected error
content:
application/json; charset=utf-8:
schema:
$ref: '#/components/schemas/Error'
/attachments/{attachmentId}:
parameters:
- name: attachmentId
in: path
required: true
schema:
$ref: '#/components/schemas/EntityId'
get:
description: Returns an attachment identified by its ID
operationId: getAttachmentById
responses:
'200':
description: attachment response
content:
application/json; charset=utf-8:
schema:
$ref: '#/components/schemas/Attachment'
default:
description: unexpected error
content:
application/json; charset=utf-8:
schema:
$ref: '#/components/schemas/Error'
patch:
description: patch an attachment identified by the attachmentId with changes in the body. Only role, mime, title, and position are patchable.
operationId: patchAttachmentById
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Attachment'
responses:
'200':
description: attribute updated
content:
application/json; charset=utf-8:
schema:
$ref: '#/components/schemas/Attachment'
default:
description: unexpected error
content:
application/json; charset=utf-8:
schema:
$ref: '#/components/schemas/Error'
delete:
description: deletes an attachment based on the attachmentId supplied.
operationId: deleteAttachmentById
responses:
'204':
description: attachment deleted
default:
description: unexpected error
content:
application/json; charset=utf-8:
schema:
$ref: '#/components/schemas/Error'
/attachments/{attachmentId}/content:
parameters:
- name: attachmentId
in: path
required: true
schema:
$ref: '#/components/schemas/EntityId'
get:
description: Returns attachment content identified by its ID
operationId: getAttachmentContent
responses:
'200':
description: attachment content response
content:
text/html:
schema:
type: string
put:
description: Updates attachment content identified by its ID
operationId: putAttachmentContentById
requestBody:
description: html content of attachment
required: true
content:
text/plain:
schema:
type: string
responses:
'204':
description: attachment content updated
/attributes:
post:
description: create an attribute for a given note
Expand Down Expand Up @@ -474,7 +584,7 @@ paths:
schema:
$ref: '#/components/schemas/Error'
patch:
description: patch a attribute identified by the attributeId with changes in the body. For labels, only value and position can be updated. For relations, only position can be updated. If you want to modify other properties, you need to delete the old attribute and create a new one.
description: patch an attribute identified by the attributeId with changes in the body. For labels, only value and position can be updated. For relations, only position can be updated. If you want to modify other properties, you need to delete the old attribute and create a new one.
operationId: patchAttributeById
requestBody:
required: true
Expand All @@ -496,7 +606,7 @@ paths:
schema:
$ref: '#/components/schemas/Error'
delete:
description: deletes a attribute based on the attributeId supplied.
description: deletes an attribute based on the attributeId supplied.
operationId: deleteAttributeById
responses:
'204':
Expand Down Expand Up @@ -884,6 +994,57 @@ components:
$ref: '#/components/schemas/Note'
branch:
$ref: '#/components/schemas/Branch'
Attachment:
type: object
description: Attachment is owned by a note, has title and content
properties:
attachmentId:
$ref: '#/components/schemas/EntityId'
readOnly: true
ownerId:
$ref: '#/components/schemas/EntityId'
description: identifies the owner of the attachment, is either noteId or revisionId
role:
type: string
mime:
type: string
title:
type: string
position:
type: integer
format: int32
blobId:
type: string
description: ID of the blob object which effectively serves as a content hash
dateModified:
$ref: '#/components/schemas/LocalDateTime'
readOnly: true
utcDateModified:
$ref: '#/components/schemas/UtcDateTime'
readOnly: true
utcDateScheduledForErasureSince:
$ref: '#/components/schemas/UtcDateTime'
readOnly: true
contentLength:
type: integer
format: int32
CreateAttachment:
type: object
properties:
ownerId:
$ref: '#/components/schemas/EntityId'
description: identifies the owner of the attachment, is either noteId or revisionId
role:
type: string
mime:
type: string
title:
type: string
content:
type: string
position:
type: integer
format: int32
Attribute:
type: object
description: Attribute (Label, Relation) is a key-value record attached to a note.
Expand Down
8 changes: 5 additions & 3 deletions src/services/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ async function downloadImage(noteId, imageUrl) {
const title = path.basename(parsedUrl.pathname);

const imageService = require('../services/image.js');
const {attachment} = imageService.saveImageToAttachment(noteId, imageBuffer, title, true, true);
const attachment = imageService.saveImageToAttachment(noteId, imageBuffer, title, true, true);

imageUrlToAttachmentIdMapping[imageUrl] = attachment.attachmentId;

Expand All @@ -511,15 +511,15 @@ const downloadImagePromises = {};
function replaceUrl(content, url, attachment) {
const quotedUrl = utils.quoteRegex(url);

return content.replace(new RegExp(`\\s+src=[\"']${quotedUrl}[\"']`, "ig"), ` src="api/attachments/${encodeURIComponent(attachment.title)}/image"`);
return content.replace(new RegExp(`\\s+src=[\"']${quotedUrl}[\"']`, "ig"), ` src="api/attachments/${attachment.attachmentId}/image/${encodeURIComponent(attachment.title)}"`);
}

function downloadImages(noteId, content) {
const imageRe = /<img[^>]*?\ssrc=['"]([^'">]+)['"]/ig;
let imageMatch;

while (imageMatch = imageRe.exec(content)) {
const url = imageMatch[1];
let url = imageMatch[1];
const inlineImageMatch = /^data:image\/[a-z]+;base64,/.exec(url);

if (inlineImageMatch) {
Expand All @@ -541,6 +541,8 @@ function downloadImages(noteId, content) {
continue;
}

url = utils.unescapeHtml(url);

if (url in imageUrlToAttachmentIdMapping) {
const attachment = becca.getAttachment(imageUrlToAttachmentIdMapping[url]);

Expand Down
8 changes: 4 additions & 4 deletions src/share/content_renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ function renderText(result, note) {

if (result.content.includes(`<span class="math-tex">`)) {
result.header += `
<script src="../../${assetPath}/libraries/katex/katex.min.js"></script>
<link rel="stylesheet" href="../../${assetPath}/libraries/katex/katex.min.css">
<script src="../../${assetPath}/libraries/katex/auto-render.min.js"></script>
<script src="../../${assetPath}/libraries/katex/mhchem.min.js"></script>
<script src="../../${assetPath}/node_modules/katex/dist/katex.min.js"></script>
<link rel="stylesheet" href="../../${assetPath}/node_modules/katex/dist/katex.min.css">
<script src="../../${assetPath}/node_modules/katex/dist/contrib/auto-render.min.js"></script>
<script src="../../${assetPath}/node_modules/katex/dist/contrib/mhchem.min.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function() {
renderMathInElement(document.getElementById('content'));
Expand Down

0 comments on commit e2cb3c0

Please sign in to comment.