|
1542 | 1542 | file-path (str block-id "." ext)
|
1543 | 1543 | file-rpath (str asset-dir-rpath "/" file-path)
|
1544 | 1544 | dir repo-dir
|
1545 |
| - asset (db/entity :logseq.class/Asset) |
1546 |
| - properties {:logseq.property.asset/type ext |
1547 |
| - :logseq.property.asset/size (.-size file) |
1548 |
| - :logseq.property.asset/checksum checksum |
1549 |
| - :block/tags (:db/id asset)} |
1550 |
| - insert-opts {:custom-uuid block-id |
1551 |
| - :edit-block? false |
1552 |
| - :properties properties} |
1553 |
| - _ (db-based-save-asset! repo dir file file-rpath) |
1554 |
| - edit-block (or (state/get-edit-block) last-edit-block) |
1555 |
| - today-page-name (date/today) |
1556 |
| - today-page-e (db-model/get-journal-page today-page-name) |
1557 |
| - today-page (if (nil? today-page-e) |
1558 |
| - (state/pub-event! [:page/create today-page-name]) |
1559 |
| - today-page-e) |
1560 |
| - insert-to-current-block-page? (and (:block/uuid edit-block) (not pdf-area?)) |
1561 |
| - insert-opts' (if insert-to-current-block-page? |
1562 |
| - (assoc insert-opts |
1563 |
| - :block-uuid (:block/uuid edit-block) |
1564 |
| - :replace-empty-target? true |
1565 |
| - :sibling? true) |
1566 |
| - (assoc insert-opts :page (:block/uuid today-page))) |
1567 |
| - new-block (api-insert-new-block! file-name-without-ext insert-opts')] |
1568 |
| - (when insert-to-current-block-page? |
1569 |
| - (state/clear-edit!)) |
1570 |
| - (or new-block |
1571 |
| - (throw (ex-info "Can't save asset" {:files files})))))))))) |
| 1545 | + asset (db/entity :logseq.class/Asset)] |
| 1546 | + |
| 1547 | + (if (> (.-size file) (* 100 1024 1024)) ; 100m |
| 1548 | + (do |
| 1549 | + (notification/show! [:div "Asset size shouldn't be larger than 100M"] |
| 1550 | + :error |
| 1551 | + false) |
| 1552 | + (throw (ex-info "Asset size shouldn't be larger than 100M" {:file-name file-name}))) |
| 1553 | + (p/let [properties {:logseq.property.asset/type ext |
| 1554 | + :logseq.property.asset/size (.-size file) |
| 1555 | + :logseq.property.asset/checksum checksum |
| 1556 | + :block/tags (:db/id asset)} |
| 1557 | + insert-opts {:custom-uuid block-id |
| 1558 | + :edit-block? false |
| 1559 | + :properties properties} |
| 1560 | + _ (db-based-save-asset! repo dir file file-rpath) |
| 1561 | + edit-block (or (state/get-edit-block) last-edit-block) |
| 1562 | + today-page-name (date/today) |
| 1563 | + today-page-e (db-model/get-journal-page today-page-name) |
| 1564 | + today-page (if (nil? today-page-e) |
| 1565 | + (state/pub-event! [:page/create today-page-name]) |
| 1566 | + today-page-e) |
| 1567 | + insert-to-current-block-page? (and (:block/uuid edit-block) (not pdf-area?)) |
| 1568 | + insert-opts' (if insert-to-current-block-page? |
| 1569 | + (assoc insert-opts |
| 1570 | + :block-uuid (:block/uuid edit-block) |
| 1571 | + :replace-empty-target? true |
| 1572 | + :sibling? true) |
| 1573 | + (assoc insert-opts :page (:block/uuid today-page))) |
| 1574 | + new-block (api-insert-new-block! file-name-without-ext insert-opts')] |
| 1575 | + (when insert-to-current-block-page? |
| 1576 | + (state/clear-edit!)) |
| 1577 | + (or new-block |
| 1578 | + (throw (ex-info "Can't save asset" {:files files})))))))))))) |
1572 | 1579 |
|
1573 | 1580 | (def insert-command! editor-common-handler/insert-command!)
|
1574 | 1581 |
|
|
0 commit comments