Skip to content

Commit

Permalink
0.5.11
Browse files Browse the repository at this point in the history
Add WebM files
  • Loading branch information
alangrainger committed Oct 12, 2023
2 parents 8629dd8 + 2a74f4a commit b557e89
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "share-note",
"name": "Share Note",
"version": "0.5.10",
"version": "0.5.11",
"minAppVersion": "0.15.0",
"description": "Instantly share a note, with all theme and content supported exactly like you see in Reading View. Data is shared encrypted by default and only you have the key.",
"author": "Alan Grainger",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "share-note",
"version": "0.5.11",
"description": "Instantly share a note, with all theme and content supported exactly like you see in Reading View. Data is shared encrypted by default and only you have the key.",
"main": "main.js",
"scripts": {
Expand Down
10 changes: 10 additions & 0 deletions src/StatusMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ const statuses: { [key: number]: StatusAttributes } = {
}

export default class StatusMessage extends Notice {
messageEl: HTMLDivElement
icon: string

constructor (text: string, type: StatusType = StatusType.Default, duration = 5000) {
const messageDoc = new DocumentFragment()

const icon = statuses[type]?.icon || ''
const messageEl = messageDoc.createEl('div', {
text: `${icon}${pluginName}: ${text}`
Expand All @@ -42,5 +46,11 @@ export default class StatusMessage extends Notice {
messageEl.parentElement.classList.add(statuses[type].class)
}
}
this.icon = icon
this.messageEl = messageEl
}

setStatus (message: string) {
this.messageEl.innerText = `${this.icon}${pluginName}: ${message}`
}
}
1 change: 0 additions & 1 deletion src/libraries/FileTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class FileTypes {
signature = new Uint8Array(signature, 0, 10)
}
const type = types.find(library => library.signature && this.bufferIsEqual(library.signature, signature as Uint8Array))
console.log(type)
return type ? new FileType(type) : undefined
}

Expand Down
14 changes: 9 additions & 5 deletions src/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default class Note {

async share () {
// Create a semi-permanent status notice which we can update
this.status = new StatusMessage('Sharing note...', StatusType.Default, 30 * 1000)
this.status = new StatusMessage('Processing note...', StatusType.Default, 30 * 1000)

if (!this.plugin.settings.apiKey) {
window.open(this.plugin.settings.server + '/v1/account/get-key?id=' + this.plugin.settings.uid)
Expand Down Expand Up @@ -142,7 +142,7 @@ export default class Note {

// Process CSS and images
await this.uploadCss()
await this.processImages()
await this.processMedia()

/*
* Encrypt the note contents
Expand Down Expand Up @@ -175,6 +175,7 @@ export default class Note {
}

if (this.isEncrypted) {
this.status.setStatus('Encrypting note...')
const plaintext = JSON.stringify({
content: this.contentDom.body.innerHTML,
basename: title
Expand Down Expand Up @@ -215,6 +216,7 @@ export default class Note {
this.template.mathJax = !!this.contentDom.body.innerHTML.match(/<mjx-container/)

// Share the file
this.status.setStatus('Uploading note...')
let shareLink = await this.plugin.api.createNote(this.template)
requestUrl(shareLink).then().catch() // Fetch the uploaded file to pull it through the cache

Expand Down Expand Up @@ -249,12 +251,15 @@ export default class Note {
/**
* Upload images encoded as base64
*/
async processImages () {
for (const el of this.contentDom.querySelectorAll('img')) {
async processMedia () {
const elements = ['img', 'video']
let count = 1
for (const el of this.contentDom.querySelectorAll(elements.join(','))) {
const src = el.getAttribute('src')
if (!src || !src.startsWith('app://')) continue
const srcMatch = src.match(/app:\/\/\w+\/([^?#]+)/)
if (!srcMatch) continue
this.status.setStatus('Processing attachment ' + (count++) + '...')
const localFile = window.decodeURIComponent(srcMatch[1])
const content = await FileSystemAdapter.readLocalFile(localFile)
const filetype = localFile.split('.').pop()
Expand Down Expand Up @@ -368,7 +373,6 @@ export default class Note {
* @param {string} mimeType
* @return {string|undefined}
*/

extensionFromMime (mimeType: string) {
const mimes = cssAttachmentWhitelist
return Object.keys(mimes).find(x => mimes[x].includes((mimeType || '').toLowerCase()))
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"0.5.7": "0.15.0",
"0.5.8": "0.15.0",
"0.5.9": "0.15.0",
"0.5.10": "0.15.0"
"0.5.10": "0.15.0",
"0.5.11": "0.15.0"
}

0 comments on commit b557e89

Please sign in to comment.