pixelfed/public/js/story-compose.js

1 line
22 KiB
JavaScript
Raw Normal View History

2022-12-07 08:10:46 +00:00
(self.webpackChunkpixelfed=self.webpackChunkpixelfed||[]).push([[645],{5392:(t,e,i)=>{"use strict";i.r(e),i.d(e,{default:()=>r});var a=i(92987),s=i(17652),o=(i(70461),i(19755));function n(t){return function(t){if(Array.isArray(t))return l(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(!t)return;if("string"==typeof t)return l(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);"Object"===i&&t.constructor&&(i=t.constructor.name);if("Map"===i||"Set"===i)return Array.from(t);if("Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i))return l(t,e)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function l(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,a=new Array(e);i<e;i++)a[i]=t[i];return a}const r={components:{VueCropper:s.default,VueTimeago:a.default},props:["profile-id"],data:function(){return{loaded:!1,config:window.App.config,mimes:["image/jpeg","image/png","video/mp4"],page:"landing",pages:["landing","crop","edit","confirm","error","uploading","createPoll"],uploading:!1,uploadProgress:0,cropper:{aspectRatio:9/16,viewMode:3,zoomable:!0,zoom:null},mediaUrl:null,mediaId:null,mediaType:null,stories:[],lightboxMedia:!1,duration:10,canReply:!0,canReact:!0,poll:{question:null,options:[]},pollQuestion:null,pollOptions:[],canPostPoll:!1,max_duration:15}},watch:{duration:function(t){"video"==this.mediaType&&(this.$refs.previewVideo.currentTime=t,this.$refs.previewVideo.play())},pollQuestion:function(t){t.length<6&&(this.canPostPoll=!1)},pollOptions:function(t){this.pollOptions.filter((function(t){return t.length>=2})).length>=2?this.canPostPoll=!0:this.canPostPoll=!1}},mounted:function(){var t=this;o("body").addClass("bg-black"),this.mediaWatcher(),setTimeout((function(){axios.get("/api/web/stories/v1/profile/"+t.profileId).then((function(e){e.data.length&&(t.stories=e.data[0].nodes.map((function(t){return t.showViewers=!1,t.viewers=[],t}))),t.loaded=!0}))}),400)},methods:{upload:function(){o('.file-input[name="media"]').trigger("click")},mediaWatcher:function(){var t=this;o(document).on("change","#pf-dz",(function(e){t.triggerUpload()}))},triggerUpload:function(){var t=this;t.uploading=!0;var e=document.querySelector("#pf-dz");t.page="uploading",Array.prototype.forEach.call(e.files,(function(e,i){if(t.media&&t.media.length+i>=t.config.uploader.album_limit)return swal("Error","You can only upload "+t.config.uploader.album_limit+" photos per album","error"),t.uploading=!1,void(t.page=2);var a=e.type;if(-1==o.inArray(a,t.mimes))return swal("Invalid File Type","The file you are trying to add is not a valid mime type. Please upload a "+t.mimes+" only.","error"),t.uploading=!1,void(t.page="error");var s=new FormData;s.append("file",e);var n={onUploadProgress:function(e){var i=Math.floor(100*e.loaded/e.total);t.uploadProgress=i}};e.value=null,axios.post("/api/web/stories/v1/add",s,n).then((function(e){t.uploadProgress=100,t.uploading=!1,t.mediaUrl=e.data.media_url,t.mediaId=e.data.media_id,t.mediaType=e.data.media_type,t.page="video"===e.data.media_type?"preview":"crop",e.data.hasOwnProperty("media_duration")&&(t.max_duration=e.data.media_duration)})).catch((function(i){t.uploading=!1,e.value=null;var a=i.response.data.message?i.response.data.message:i.response.data.error?i.response.data.error:"Something went wrong.";swal("Oops!",a,"warning"),t.page="error"})),t.uploadProgress=0})),document.querySelector("#pf-dz").value=""},expiresTimestamp:function(t){return(t=new Date(1e3*t)).toDateString()+" "+t.toLocaleTimeString()},edit:function(){this.page="edit"},showLightbox:function(t){this.lightboxMedia={url:t.src},this.$refs.lightboxModal.show()},deleteStory:function(t,e){var i=this;1==window.confirm("Are you sure you want to delete this Story?")&&axios.delete("/api/web/stories/v1/delete/"+t.id).then((function(t){i.stories.splice(e,1),0==i.stories.length&&(window.location.href="/i/stories/new")}))}