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 (5455B)


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