logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://anongit.hacktivis.me/git/pleroma-fe.git/

attachment.js (5503B)


  1. import StillImage from '../still-image/still-image.vue'
  2. import Flash from '../flash/flash.vue'
  3. import VideoAttachment from '../video_attachment/video_attachment.vue'
  4. import nsfwImage from '../../assets/nsfw.png'
  5. import fileTypeService from '../../services/file_type/file_type.service.js'
  6. import { mapGetters } from 'vuex'
  7. import { library } from '@fortawesome/fontawesome-svg-core'
  8. import {
  9. faFile,
  10. faMusic,
  11. faImage,
  12. faVideo,
  13. faPlayCircle,
  14. faTimes,
  15. faStop,
  16. faSearchPlus,
  17. faTrashAlt,
  18. faPencilAlt,
  19. faAlignRight
  20. } from '@fortawesome/free-solid-svg-icons'
  21. import { useMediaViewerStore } from 'src/stores/media_viewer'
  22. library.add(
  23. faFile,
  24. faMusic,
  25. faImage,
  26. faVideo,
  27. faPlayCircle,
  28. faTimes,
  29. faStop,
  30. faSearchPlus,
  31. faTrashAlt,
  32. faPencilAlt,
  33. faAlignRight
  34. )
  35. const Attachment = {
  36. props: [
  37. 'attachment',
  38. 'compact',
  39. 'description',
  40. 'hideDescription',
  41. 'nsfw',
  42. 'size',
  43. 'setMedia',
  44. 'remove',
  45. 'shiftUp',
  46. 'shiftDn',
  47. 'edit'
  48. ],
  49. data () {
  50. return {
  51. localDescription: this.description || this.attachment.description,
  52. nsfwImage: this.$store.state.instance.nsfwCensorImage || nsfwImage,
  53. hideNsfwLocal: this.$store.getters.mergedConfig.hideNsfw,
  54. preloadImage: this.$store.getters.mergedConfig.preloadImage,
  55. loading: false,
  56. img: fileTypeService.fileType(this.attachment.mimetype) === 'image' && document.createElement('img'),
  57. modalOpen: false,
  58. showHidden: false,
  59. flashLoaded: false,
  60. showDescription: false
  61. }
  62. },
  63. components: {
  64. Flash,
  65. StillImage,
  66. VideoAttachment
  67. },
  68. computed: {
  69. classNames () {
  70. return [
  71. {
  72. '-loading': this.loading,
  73. '-nsfw-placeholder': this.hidden,
  74. '-editable': this.edit !== undefined,
  75. '-compact': this.compact
  76. },
  77. '-type-' + this.type,
  78. this.size && '-size-' + this.size,
  79. `-${this.useContainFit ? 'contain' : 'cover'}-fit`
  80. ]
  81. },
  82. usePlaceholder () {
  83. return this.size === 'hide'
  84. },
  85. useContainFit () {
  86. return this.$store.getters.mergedConfig.useContainFit
  87. },
  88. placeholderName () {
  89. if (this.attachment.description === '' || !this.attachment.description) {
  90. return this.type.toUpperCase()
  91. }
  92. return this.attachment.description
  93. },
  94. placeholderIconClass () {
  95. if (this.type === 'image') return 'image'
  96. if (this.type === 'video') return 'video'
  97. if (this.type === 'audio') return 'music'
  98. return 'file'
  99. },
  100. referrerpolicy () {
  101. return this.$store.state.instance.mediaProxyAvailable ? '' : 'no-referrer'
  102. },
  103. type () {
  104. return fileTypeService.fileType(this.attachment.mimetype)
  105. },
  106. hidden () {
  107. return this.nsfw && this.hideNsfwLocal && !this.showHidden
  108. },
  109. isEmpty () {
  110. return (this.type === 'html' && !this.attachment.oembed)
  111. },
  112. useModal () {
  113. let modalTypes = []
  114. switch (this.size) {
  115. case 'hide':
  116. case 'small':
  117. modalTypes = ['image', 'video', 'audio', 'flash']
  118. break
  119. default:
  120. modalTypes = this.mergedConfig.playVideosInModal
  121. ? ['image', 'video', 'flash']
  122. : ['image']
  123. break
  124. }
  125. return modalTypes.includes(this.type)
  126. },
  127. videoTag () {
  128. return this.useModal ? 'button' : 'span'
  129. },
  130. ...mapGetters(['mergedConfig'])
  131. },
  132. watch: {
  133. 'attachment.description' (newVal) {
  134. this.localDescription = newVal
  135. },
  136. localDescription (newVal) {
  137. this.onEdit(newVal)
  138. }
  139. },
  140. methods: {
  141. linkClicked ({ target }) {
  142. if (target.tagName === 'A') {
  143. window.open(target.href, '_blank')
  144. }
  145. },
  146. openModal () {
  147. if (this.useModal) {
  148. this.$emit('setMedia')
  149. useMediaViewerStore().setCurrentMedia(this.attachment)
  150. } else if (this.type === 'unknown') {
  151. window.open(this.attachment.url)
  152. }
  153. },
  154. openModalForce () {
  155. this.$emit('setMedia')
  156. useMediaViewerStore().setCurrentMedia(this.attachment)
  157. },
  158. onEdit (event) {
  159. this.edit && this.edit(this.attachment, event)
  160. },
  161. onRemove () {
  162. this.remove && this.remove(this.attachment)
  163. },
  164. onShiftUp () {
  165. this.shiftUp && this.shiftUp(this.attachment)
  166. },
  167. onShiftDn () {
  168. this.shiftDn && this.shiftDn(this.attachment)
  169. },
  170. stopFlash () {
  171. this.$refs.flash.closePlayer()
  172. },
  173. setFlashLoaded (event) {
  174. this.flashLoaded = event
  175. },
  176. toggleDescription () {
  177. this.showDescription = !this.showDescription
  178. },
  179. toggleHidden (event) {
  180. if (
  181. (this.mergedConfig.useOneClickNsfw && !this.showHidden) &&
  182. (this.type !== 'video' || this.mergedConfig.playVideosInModal)
  183. ) {
  184. this.openModal(event)
  185. return
  186. }
  187. if (this.img && !this.preloadImage) {
  188. if (this.img.onload) {
  189. this.img.onload()
  190. } else {
  191. this.loading = true
  192. this.img.src = this.attachment.url
  193. this.img.onload = () => {
  194. this.loading = false
  195. this.showHidden = !this.showHidden
  196. }
  197. }
  198. } else {
  199. this.showHidden = !this.showHidden
  200. }
  201. },
  202. onImageLoad (image) {
  203. const width = image.naturalWidth
  204. const height = image.naturalHeight
  205. this.$emit('naturalSizeLoad', { id: this.attachment.id, width, height })
  206. }
  207. }
  208. }
  209. export default Attachment