pixelfed/public/js/story-compose.js

1 line
13 KiB
JavaScript
Raw Permalink Normal View History

2024-07-23 07:31:06 +00:00
(self.webpackChunkpixelfed=self.webpackChunkpixelfed||[]).push([[4822],{13574:(t,e,a)=>{"use strict";a.r(e),a.d(e,{default:()=>o});var i=a(24786),s=a(91584),r=(a(77333),a(74692));const o={components:{VueCropper:s.default,VueTimeago:i.default},props:["profile-id"],data:function(){return{loaded:!1,config:window.App.config,mimes:["image/jpeg","image/png"],page:"landing",pages:["landing","crop","edit","confirm","error","uploading"],uploading:!1,uploadProgress:0,cropper:{aspectRatio:9/16,viewMode:2,zoomable:!0,zoom:null},mediaUrl:null,mediaId:null,stories:[],lightboxMedia:!1,duration:3}},mounted:function(){var t=this;r("body").addClass("bg-black"),this.mediaWatcher(),axios.get("/api/stories/v0/fetch/"+this.profileId).then((function(e){t.stories=e.data.map((function(t){return t.showViewers=!1,t.viewers=[],t})),t.loaded=!0}))},methods:{upload:function(){r('.file-input[name="media"]').trigger("click")},mediaWatcher:function(){var t=this;r(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,a){if(t.media&&t.media.length+a>=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 i=e.type;if(-1==r.inArray(i,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 o={onUploadProgress:function(e){var a=Math.floor(100*e.loaded/e.total);t.uploadProgress=a}};e.value=null,axios.post("/api/stories/v0/add",s,o).then((function(e){t.uploadProgress=100,t.uploading=!1,t.mediaUrl=e.data.media_url,t.mediaId=e.data.media_id,t.page="video"===e.data.media_type?"preview":"crop"})).catch((function(a){t.uploading=!1,e.value=null;var i=a.response.data.message?a.response.data.message:"Something went wrong.";swal("Oops!",i,"warning"),t.page="error"})),t.uploadProgress=0}))},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 a=this;1==window.confirm("Are you sure you want to delete this Story?")&&axios.delete("/api/stories/v0/delete/"+t.id).then((function(t){a.stories.splice(e,1),0==a.stories.length&&(window.location.href="/i/stories/new")}))},navigateTo:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"/";window.location.href=t},goBack:function(){this.page="landing"},performCrop:function(){var t=this;this.page="cropping";var e=this.$refs.croppa.getData();axios.post("/api/stories/v0/crop",{media_id:this.mediaId,width:e.width,height:e.height,x:e.x,y:e.y}).then((function(e){t.page="preview"}))},deleteCurrentStory:function(){var t={id:this.mediaId};this.deleteStory(t),this.page="landing"},shareStoryToFollowers:function(){var t=this;axios.post("/api/stories/v0/publish",{media_id:this.mediaId,duration:this.duration}).then((function(e){window.location.href="/i/my/story?id="+t.mediaId}))},viewMyStory:function(){window.location.href="/i/my/story"},toggleShowViewers:function(t){this.stories[t].showViewers=!this.stories[t].showViewers}}}},74414:(t,e,a)=>{"use strict";a.r(e),a.d(e,{render:()=>i,staticRenderFns:()=>s});var i=function(){var t=this,e=t._self._c;return e("div",{staticClass:"container mt-2 mt-md-5 bg-black"},[e("input",{staticClass:"d-none file-input",attrs:{type:"file",id:"pf-dz",name:"media",accept:t.config.mimes}}),t._v(" "),e("span",{staticClass:"fixed-top text-right m-3 cursor-pointer",on:{click:function(e){return t.navigateTo()}}},[e("i",{staticClass:"fas fa-times fa-lg text-white"})]),t._v(" "),t.loaded?e("div",{staticClass:"row"},[e("div",{staticClass:"col-12 col-md-6 offset-md-3 bg-dark rounded-lg"},["landing"==t.page?e("div",{staticClass:"card card-body bg-transparent border-0 shadow-non