mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-11-04 15:11:31 +08:00 
			
		
		
		
	renamed "attachment" to "file" for consistency
This commit is contained in:
		
							parent
							
								
									913b6bb6f6
								
							
						
					
					
						commit
						7464835058
					
				@ -1,7 +1,7 @@
 | 
			
		||||
import utils from "./utils.js";
 | 
			
		||||
import treeService from "./tree.js";
 | 
			
		||||
import linkService from "./link.js";
 | 
			
		||||
import attachmentService from "./attachment.js";
 | 
			
		||||
import fileService from "./file.js";
 | 
			
		||||
import noteRevisionsDialog from "../dialogs/note_revisions.js";
 | 
			
		||||
import settingsDialog from "../dialogs/settings.js";
 | 
			
		||||
import addLinkDialog from "../dialogs/add_link.js";
 | 
			
		||||
@ -125,7 +125,7 @@ function registerEntrypoints() {
 | 
			
		||||
 | 
			
		||||
    $("#note-title").bind('keydown', 'return', () => $("#note-detail-text").focus());
 | 
			
		||||
 | 
			
		||||
    $("#upload-attachment-button").click(attachmentService.uploadAttachment);
 | 
			
		||||
    $("#upload-file-button").click(fileService.uploadFile);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export default {
 | 
			
		||||
 | 
			
		||||
@ -2,16 +2,16 @@ import noteDetailService from "./note_detail.js";
 | 
			
		||||
import treeService from "./tree.js";
 | 
			
		||||
import server from "./server.js";
 | 
			
		||||
 | 
			
		||||
function uploadAttachment() {
 | 
			
		||||
    $("#attachment-upload").trigger('click');
 | 
			
		||||
function uploadFile() {
 | 
			
		||||
    $("#file-upload").trigger('click');
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
$("#attachment-upload").change(async function() {
 | 
			
		||||
$("#file-upload").change(async function() {
 | 
			
		||||
    const formData = new FormData();
 | 
			
		||||
    formData.append('upload', this.files[0]);
 | 
			
		||||
 | 
			
		||||
    const resp = await $.ajax({
 | 
			
		||||
        url: baseApiUrl + 'attachments/upload/' + noteDetailService.getCurrentNoteId(),
 | 
			
		||||
        url: baseApiUrl + 'files/upload/' + noteDetailService.getCurrentNoteId(),
 | 
			
		||||
        headers: server.getHeaders(),
 | 
			
		||||
        data: formData,
 | 
			
		||||
        type: 'POST',
 | 
			
		||||
@ -25,5 +25,5 @@ $("#attachment-upload").change(async function() {
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
export default {
 | 
			
		||||
    uploadAttachment
 | 
			
		||||
    uploadFile
 | 
			
		||||
}
 | 
			
		||||
@ -10,7 +10,7 @@ import treeCache from "./tree_cache.js";
 | 
			
		||||
import NoteFull from "../entities/note_full.js";
 | 
			
		||||
import noteDetailCode from './note_detail_code.js';
 | 
			
		||||
import noteDetailText from './note_detail_text.js';
 | 
			
		||||
import noteDetailAttachment from './note_detail_attachment.js';
 | 
			
		||||
import noteDetailFile from './note_detail_file.js';
 | 
			
		||||
import noteDetailSearch from './note_detail_search.js';
 | 
			
		||||
import noteDetailRender from './note_detail_render.js';
 | 
			
		||||
 | 
			
		||||
@ -34,7 +34,7 @@ let isNoteChanged = false;
 | 
			
		||||
const components = {
 | 
			
		||||
    'code': noteDetailCode,
 | 
			
		||||
    'text': noteDetailText,
 | 
			
		||||
    'file': noteDetailAttachment,
 | 
			
		||||
    'file': noteDetailFile,
 | 
			
		||||
    'search': noteDetailSearch,
 | 
			
		||||
    'render': noteDetailRender
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -1,50 +0,0 @@
 | 
			
		||||
import utils from "./utils.js";
 | 
			
		||||
import server from "./server.js";
 | 
			
		||||
import protectedSessionHolder from "./protected_session_holder.js";
 | 
			
		||||
import noteDetailService from "./note_detail.js";
 | 
			
		||||
 | 
			
		||||
const $noteDetailAttachment = $('#note-detail-attachment');
 | 
			
		||||
 | 
			
		||||
const $attachmentFileName = $("#attachment-filename");
 | 
			
		||||
const $attachmentFileType = $("#attachment-filetype");
 | 
			
		||||
const $attachmentFileSize = $("#attachment-filesize");
 | 
			
		||||
const $attachmentDownload = $("#attachment-download");
 | 
			
		||||
const $attachmentOpen = $("#attachment-open");
 | 
			
		||||
 | 
			
		||||
async function show() {
 | 
			
		||||
    const currentNote = noteDetailService.getCurrentNote();
 | 
			
		||||
 | 
			
		||||
    const labels = await server.get('notes/' + currentNote.noteId + '/labels');
 | 
			
		||||
    const labelMap = utils.toObject(labels, l => [l.name, l.value]);
 | 
			
		||||
 | 
			
		||||
    $noteDetailAttachment.show();
 | 
			
		||||
 | 
			
		||||
    $attachmentFileName.text(labelMap.original_file_name);
 | 
			
		||||
    $attachmentFileSize.text(labelMap.file_size + " bytes");
 | 
			
		||||
    $attachmentFileType.text(currentNote.mime);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
$attachmentDownload.click(() => utils.download(getAttachmentUrl()));
 | 
			
		||||
 | 
			
		||||
$attachmentOpen.click(() => {
 | 
			
		||||
    if (utils.isElectron()) {
 | 
			
		||||
        const open = require("open");
 | 
			
		||||
 | 
			
		||||
        open(getAttachmentUrl());
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
        window.location.href = getAttachmentUrl();
 | 
			
		||||
    }
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
function getAttachmentUrl() {
 | 
			
		||||
    // electron needs absolute URL so we extract current host, port, protocol
 | 
			
		||||
    return utils.getHost() + "/api/attachments/download/" + noteDetailService.getCurrentNoteId()
 | 
			
		||||
        + "?protectedSessionId=" + encodeURIComponent(protectedSessionHolder.getProtectedSessionId());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export default {
 | 
			
		||||
    show,
 | 
			
		||||
    getContent: () => null,
 | 
			
		||||
    focus: () => null
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										50
									
								
								src/public/javascripts/services/note_detail_file.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								src/public/javascripts/services/note_detail_file.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,50 @@
 | 
			
		||||
import utils from "./utils.js";
 | 
			
		||||
import server from "./server.js";
 | 
			
		||||
import protectedSessionHolder from "./protected_session_holder.js";
 | 
			
		||||
import noteDetailService from "./note_detail.js";
 | 
			
		||||
 | 
			
		||||
const $noteDetailFile = $('#note-detail-file');
 | 
			
		||||
 | 
			
		||||
const $fileFileName = $("#file-filename");
 | 
			
		||||
const $fileFileType = $("#file-filetype");
 | 
			
		||||
const $fileFileSize = $("#file-filesize");
 | 
			
		||||
const $fileDownload = $("#file-download");
 | 
			
		||||
const $fileOpen = $("#file-open");
 | 
			
		||||
 | 
			
		||||
async function show() {
 | 
			
		||||
    const currentNote = noteDetailService.getCurrentNote();
 | 
			
		||||
 | 
			
		||||
    const labels = await server.get('notes/' + currentNote.noteId + '/labels');
 | 
			
		||||
    const labelMap = utils.toObject(labels, l => [l.name, l.value]);
 | 
			
		||||
 | 
			
		||||
    $noteDetailFile.show();
 | 
			
		||||
 | 
			
		||||
    $fileFileName.text(labelMap.original_file_name);
 | 
			
		||||
    $fileFileSize.text(labelMap.file_size + " bytes");
 | 
			
		||||
    $fileFileType.text(currentNote.mime);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
$fileDownload.click(() => utils.download(getFileUrl()));
 | 
			
		||||
 | 
			
		||||
$fileOpen.click(() => {
 | 
			
		||||
    if (utils.isElectron()) {
 | 
			
		||||
        const open = require("open");
 | 
			
		||||
 | 
			
		||||
        open(getFileUrl());
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
        window.location.href = getFileUrl();
 | 
			
		||||
    }
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
function getFileUrl() {
 | 
			
		||||
    // electron needs absolute URL so we extract current host, port, protocol
 | 
			
		||||
    return utils.getHost() + "/api/files/download/" + noteDetailService.getCurrentNoteId()
 | 
			
		||||
        + "?protectedSessionId=" + encodeURIComponent(protectedSessionHolder.getProtectedSessionId());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export default {
 | 
			
		||||
    show,
 | 
			
		||||
    getContent: () => null,
 | 
			
		||||
    focus: () => null
 | 
			
		||||
}
 | 
			
		||||
@ -69,7 +69,7 @@ function NoteTypeModel() {
 | 
			
		||||
            return 'Render HTML note';
 | 
			
		||||
        }
 | 
			
		||||
        else if (type === 'file') {
 | 
			
		||||
            return 'Attachment';
 | 
			
		||||
            return 'File';
 | 
			
		||||
        }
 | 
			
		||||
        else if (type === 'search') {
 | 
			
		||||
            // ignore and do nothing, "type" will be hidden since it's not possible to switch to and from search
 | 
			
		||||
 | 
			
		||||
@ -285,7 +285,7 @@ div.ui-tooltip {
 | 
			
		||||
    margin-right: 5px;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#attachment-table th, #attachment-table td {
 | 
			
		||||
#file-table th, #file-table td {
 | 
			
		||||
    padding: 10px;
 | 
			
		||||
    font-size: large;
 | 
			
		||||
}
 | 
			
		||||
@ -22,7 +22,7 @@ router.get('/:noteId/', auth.checkApiAuthOrElectron, wrap(async (req, res, next)
 | 
			
		||||
 | 
			
		||||
    pack.finalize();
 | 
			
		||||
 | 
			
		||||
    res.setHeader('Content-Disposition', 'attachment; filename="' + name + '.tar"');
 | 
			
		||||
    res.setHeader('Content-Disposition', 'file; filename="' + name + '.tar"');
 | 
			
		||||
    res.setHeader('Content-Type', 'application/tar');
 | 
			
		||||
 | 
			
		||||
    pack.pipe(res);
 | 
			
		||||
 | 
			
		||||
@ -65,7 +65,7 @@ router.get('/download/:noteId', auth.checkApiAuthOrElectron, wrap(async (req, re
 | 
			
		||||
    const labelMap = await labels.getNoteLabelMap(noteId);
 | 
			
		||||
    const fileName = labelMap.original_file_name ? labelMap.original_file_name : note.title;
 | 
			
		||||
 | 
			
		||||
    res.setHeader('Content-Disposition', 'attachment; filename=' + fileName);
 | 
			
		||||
    res.setHeader('Content-Disposition', 'file; filename=' + fileName);
 | 
			
		||||
    res.setHeader('Content-Type', note.mime);
 | 
			
		||||
 | 
			
		||||
    res.send(note.content);
 | 
			
		||||
@ -26,7 +26,7 @@ router.get('/:noteId', auth.checkApiAuth, wrap(async (req, res, next) => {
 | 
			
		||||
    protected_session.decryptNote(req, detail);
 | 
			
		||||
 | 
			
		||||
    if (detail.type === 'file') {
 | 
			
		||||
        // no need to transfer (potentially large) attachment payload for this request
 | 
			
		||||
        // no need to transfer (potentially large) file payload for this request
 | 
			
		||||
        detail.content = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -29,7 +29,7 @@ const imageRoute = require('./api/image');
 | 
			
		||||
const labelsRoute = require('./api/labels');
 | 
			
		||||
const scriptRoute = require('./api/script');
 | 
			
		||||
const senderRoute = require('./api/sender');
 | 
			
		||||
const attachmentsRoute = require('./api/attachments');
 | 
			
		||||
const filesRoute = require('./api/file_upload');
 | 
			
		||||
const searchRoute = require('./api/search');
 | 
			
		||||
 | 
			
		||||
function register(app) {
 | 
			
		||||
@ -63,7 +63,7 @@ function register(app) {
 | 
			
		||||
    app.use('/api/images', imageRoute);
 | 
			
		||||
    app.use('/api/script', scriptRoute);
 | 
			
		||||
    app.use('/api/sender', senderRoute);
 | 
			
		||||
    app.use('/api/attachments', attachmentsRoute);
 | 
			
		||||
    app.use('/api/files', filesRoute);
 | 
			
		||||
    app.use('/api/search', searchRoute);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -126,7 +126,7 @@
 | 
			
		||||
              <li><a id="show-note-revisions-button">Note revisions</a></li>
 | 
			
		||||
              <li><a class="show-labels-button"><kbd>Alt+L</kbd> Labels</a></li>
 | 
			
		||||
              <li><a id="show-source-button"><kbd>Ctrl+U</kbd> HTML source</a></li>
 | 
			
		||||
              <li><a id="upload-attachment-button">Upload attachment</a></li>
 | 
			
		||||
              <li><a id="upload-file-button">Upload file</a></li>
 | 
			
		||||
            </ul>
 | 
			
		||||
          </div>
 | 
			
		||||
        </div>
 | 
			
		||||
@ -177,31 +177,31 @@
 | 
			
		||||
 | 
			
		||||
        <div id="note-detail-render" class="note-detail-component"></div>
 | 
			
		||||
 | 
			
		||||
        <div id="note-detail-attachment" class="note-detail-component">
 | 
			
		||||
          <table id="attachment-table">
 | 
			
		||||
        <div id="note-detail-file" class="note-detail-component">
 | 
			
		||||
          <table id="file-table">
 | 
			
		||||
            <tr>
 | 
			
		||||
              <th>File name:</th>
 | 
			
		||||
              <td id="attachment-filename"></td>
 | 
			
		||||
              <td id="file-filename"></td>
 | 
			
		||||
            </tr>
 | 
			
		||||
            <tr>
 | 
			
		||||
              <th>File type:</th>
 | 
			
		||||
              <td id="attachment-filetype"></td>
 | 
			
		||||
              <td id="file-filetype"></td>
 | 
			
		||||
            </tr>
 | 
			
		||||
            <tr>
 | 
			
		||||
              <th>File size:</th>
 | 
			
		||||
              <td id="attachment-filesize"></td>
 | 
			
		||||
              <td id="file-filesize"></td>
 | 
			
		||||
            </tr>
 | 
			
		||||
            <tr>
 | 
			
		||||
              <td>
 | 
			
		||||
                <button id="attachment-download" class="btn btn-primary" type="button">Download</button>
 | 
			
		||||
                <button id="file-download" class="btn btn-primary" type="button">Download</button>
 | 
			
		||||
                 
 | 
			
		||||
                <button id="attachment-open" class="btn btn-primary" type="button">Open</button>
 | 
			
		||||
                <button id="file-open" class="btn btn-primary" type="button">Open</button>
 | 
			
		||||
              </td>
 | 
			
		||||
            </tr>
 | 
			
		||||
          </table>
 | 
			
		||||
        </div>
 | 
			
		||||
 | 
			
		||||
        <input type="file" id="attachment-upload" style="display: none" />
 | 
			
		||||
        <input type="file" id="file-upload" style="display: none" />
 | 
			
		||||
      </div>
 | 
			
		||||
 | 
			
		||||
      <div id="label-list">
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user