Skip to content

Commit

Permalink
Update story && fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
5baddi committed Jan 25, 2021
1 parent c8bcfaa commit f84b492
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 87 deletions.
52 changes: 23 additions & 29 deletions app/Http/Controllers/TrackerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,29 @@ public function createStory(CreateStoryTrackerRequest $request, InstagramScraper
// Set story tracker
$story['tracker_id'] = $tracker->id;

// Upload story thumbnail
if($request->hasFile('thumbnail')){
$fileName = Str::slug($request->file('thumbnail')->getClientOriginalName()) . '_' . time() . '.' . $request->file('thumbnail')->getClientOriginalExtension();
$thumbnailPath = $request->file('thumbnail')->storeAs('influencers/instagram/temp/stories/thumbnails/', $fileName, 'local');

if($thumbnailPath)
$story['thumbnail'] = $thumbnailPath;
}

// Upload story video
if($request->hasFile('story')){
$fileName = Str::slug($request->file('story')->getClientOriginalName()) . '_' . time() . '.' . $request->file('story')->getClientOriginalExtension();
$videoPath = $request->file('thumbnail')->storeAs('influencers/instagram/temp/stories/videos/', $fileName, 'local');

if($videoPath)
$story['story'] = $videoPath;
}

// Upload story proofs
if($request->hasFile('proofs')){

}

// Verify if influencer already exists
$exists = Influencer::where([
'platform' => 'instagram',
Expand All @@ -237,35 +260,6 @@ public function createStory(CreateStoryTrackerRequest $request, InstagramScraper
}

return response()->success("Task executed in background, please wait...", [], 200);
// Create tracker
// $tracker = Tracker::create($request->validated());
// $tracker = $tracker->refresh();

// // Upload story sequences
// $medias = [];
// if($request->hasFile('story')){
// foreach($request->file('story') as $file){
// $storyFileName = Str::slug($request->input('name') . '_') . time() . '.' . $file->getClientOriginalExtension();
// $storyFilePath = $file->storeAs('uploads', $storyFileName, 'public');
// // TODO: use story table insted of tracker media
// // $medias[] = TrackerMedia::create([
// // 'tracker_id' => $tracker->id,
// // 'name' => $storyFileName,
// // 'type' => 'media',
// // 'media_path' => '/storage/' . $storyFilePath
// // ]);
// }
// }

// // Srap Influencer
// $scraper = $scraper->authenticate();
// $instagramUser = $scraper->byUsername($request->input('username'));
// $influencer = Influencer::create($instagramUser);

// return response()->success(
// "Story tracker created successfully.",
// Tracker::with(['user', 'campaign', 'shortlink', 'infleuncers'])->find($tracker->id)
// );
}

/**
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Requests/CreateStoryTrackerRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public function rules()
'type' => 'required|in:story',
'platform' => 'nullable|in:instagram,snapchat',
'username' => 'required|string',
'story' => 'required|max:50000|mimetypes:image/jpeg,image/png,image/gif,video/mp4,video/quicktime',
'thumbnail' => 'required|max:50000|mimetypes:image/jpeg,image/png,image/gif',
'story' => 'nullable|max:50000|mimetypes:video/mp4,video/quicktime',
'proofs.*' => 'nullable|max:50000|mimetypes:image/jpeg,image/png,image/gif',
'reach' => 'nullable|integer',
'impressions' => 'nullable|integer',
Expand Down
41 changes: 35 additions & 6 deletions app/Jobs/ScrapInfluencerJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@

use App\User;
use App\Influencer;
use App\StoryAnalytics;
use App\BrandInfluencer;
use Illuminate\Bus\Queueable;
use Owenoj\LaravelGetId3\GetId3;
use Illuminate\Http\UploadedFile;
use InstagramScraper\Model\Story;
use App\Services\InstagramScraper;
use Illuminate\Support\Facades\Log;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Storage;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use App\Notifications\CreateInfluencerJobState;
use App\StoryAnalytics;
use InstagramScraper\Model\Story;
use Illuminate\Support\Facades\File;

class ScrapInfluencerJob implements ShouldQueue
{
Expand Down Expand Up @@ -106,10 +110,34 @@ public function handle(InstagramScraper $instagram)

// Handle story
if(sizeof($this->story) > 0){
// Copy thumbnail
if(Storage::disk('local')->exists($this->story['thumbnail'])){
$oldPath = $this->story['thumbnail'];
$newPath = str_replace('temp', $influencer->id, $this->story['thumbnail']);
Storage::disk('local')->copy($this->story['thumbnail'], $newPath);
Storage::disk('local')->delete($oldPath);
$this->story['thumbnail'] = $newPath;
}

// Copy video
if(Storage::disk('local')->exists($this->story['story'])){
$oldPath = $this->story['story'];
$newPath = str_replace('temp', $influencer->id, $this->story['story']);
Storage::disk('local')->copy($this->story['story'], $newPath);
Storage::disk('local')->delete($oldPath);
$this->story['video'] = $newPath;

// Get video duration
$video = new GetId3(new UploadedFile(Storage::disk('local')->path($newPath), File::name($newPath)));
$this->story['video_duration'] = $video->getPlaytimeSeconds();
}

// Save story
$story = Story::create([
'influencer_id' => $influencer->id,
'tracker_id' => $this->story['tracker_id'],
'thumbnail' => $this->story['thumbnail'],
'video' => $this->story['video'],
'published_at' => $this->story['published_at']
]);

Expand All @@ -119,10 +147,11 @@ public function handle(InstagramScraper $instagram)
'reach' => $this->story['reach'],
'impressions' => $this->story['impressions'],
'interactions' => $this->story['interactions'],
'back' => $this->story['back'],
'forward' => $this->story['forward'],
'next_story' => $this->story['next_story'],
'exited' => $this->story['exited'],
'back' => $this->story['back'] ?? 0,
'forward' => $this->story['forward'] ?? 0,
'next_story' => $this->story['next_story'] ?? 0,
'exited' => $this->story['exited'] ?? 0,
'navigation' => $this->story['back'] + $this->story['forward'] + $this->story['next_story'] + $this->story['exited'],
]);
}
}
Expand Down
94 changes: 66 additions & 28 deletions public/8.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
//
//
//
//
//
//
//
//



Expand Down Expand Up @@ -325,6 +330,10 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
loadCampaigns: function loadCampaigns() {
this.$store.dispatch("fetchCampaigns")["catch"](function (e) {});
},
handleThumbnailUpload: function handleThumbnailUpload(files) {
if (typeof files[0] === "undefined") return;
this.story = files[0];
},
handleStoryUpload: function handleStoryUpload(files) {
if (typeof files[0] === "undefined") return;
this.story = files[0];
Expand Down Expand Up @@ -380,29 +389,32 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
formData.append("proofs[]", file);
}); // Dispatch the creation action

this.$store.dispatch("addNewStory", formData).then(function (response) {
_this.createTrackerSuccess({
message: "Story ".concat(response.content.name, " created successfuly!")
});

_this.$router.push({
name: 'stories'
});
})["catch"](function (error) {
var errors = Object.values(error.response.data.errors);
if (typeof this.$route.params.uuid === "undefined" || this.$route.params.uuid === null) {
this.$store.dispatch("addNewStory", formData).then(function (response) {
_this.createTrackerSuccess({
message: "Story ".concat(response.content.name, " created successfuly!")
});

if (_typeof(errors) === "object" && errors.length > 0) {
errors.forEach(function (element) {
_this.$router.push({
name: 'trackers'
});
})["catch"](function (error) {
var errors = Object.values(error.response.data.errors);

if (_typeof(errors) === "object" && errors.length > 0) {
errors.forEach(function (element) {
_this.showError({
message: element
});
});
} else {
_this.showError({
message: element
message: error.response.data.message
});
});
} else {
_this.showError({
message: error.response.data.message
});
}
});
}
});
} else {// TODO: update exists story
}
}
},
mounted: function mounted() {
Expand Down Expand Up @@ -858,24 +870,50 @@ var render = function() {
"div",
{ staticClass: "control" },
[
_c("label", [_vm._v("Story sequence")]),
_c("label", [_vm._v("Story screenshot or thumbnail")]),
_vm._v(" "),
_c("FileInput", {
attrs: {
id: "storyThumbnail",
label: "Upload story thumbnail",
accept: "image/jpeg,image/png,image/gif",
isList: true,
icon: "fas fa-plus",
multiple: false
},
on: { custom: _vm.handleThumbnailUpload }
}),
_vm._v(" "),
_c("p", [
_vm._v("A screenshot or thumbnail of story sequence.")
])
],
1
)
: _vm._e(),
_vm._v(" "),
!_vm.$route.params.uuid
? _c(
"div",
{ staticClass: "control" },
[
_c("label", [_vm._v("Story video")]),
_vm._v(" "),
_c("FileInput", {
attrs: {
id: "storyfile",
label: "Upload story sequence",
accept:
"image/jpeg,image/png,image/gif,video/mp4,video/quicktime",
id: "storyVideo",
label: "Upload story video",
accept: "video/mp4,video/quicktime",
isList: true,
icon: "fas fa-plus",
multiple: false
},
on: { custom: _vm.handleStoryUpload }
on: { custom: _vm.handleThumbnailUpload }
}),
_vm._v(" "),
_c("p", [
_vm._v(
"If there are multiple images or videos for the story, we recommend creating one story per image or video."
"If story sequence is a video upload the video sequence."
)
])
],
Expand All @@ -891,7 +929,7 @@ var render = function() {
_vm._v(" "),
_c("FileInput", {
attrs: {
id: "storyfile",
id: "storyProofs",
label: "Upload story insights screenshots",
accept: "image/jpeg,image/png,image/gif",
isList: true,
Expand Down
61 changes: 38 additions & 23 deletions resources/js/pages/trackers/story.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,18 @@
</div>
<div class="form-url">
<div class="control" v-if="!$route.params.uuid">
<label>Story sequence</label>
<FileInput v-on:custom="handleStoryUpload" v-bind:id="'storyfile'" v-bind:label="'Upload story sequence'" v-bind:accept="'image/jpeg,image/png,image/gif,video/mp4,video/quicktime'" v-bind:isList="true" v-bind:icon="'fas fa-plus'" v-bind:multiple="false"></FileInput>
<p>If there are multiple images or videos for the story, we recommend creating one story per image or video.</p>
<label>Story screenshot or thumbnail</label>
<FileInput v-on:custom="handleThumbnailUpload" v-bind:id="'storyThumbnail'" v-bind:label="'Upload story thumbnail'" v-bind:accept="'image/jpeg,image/png,image/gif'" v-bind:isList="true" v-bind:icon="'fas fa-plus'" v-bind:multiple="false"></FileInput>
<p>A screenshot or thumbnail of story sequence.</p>
</div>
<div class="control" v-if="!$route.params.uuid">
<label>Story video</label>
<FileInput v-on:custom="handleThumbnailUpload" v-bind:id="'storyVideo'" v-bind:label="'Upload story video'" v-bind:accept="'video/mp4,video/quicktime'" v-bind:isList="true" v-bind:icon="'fas fa-plus'" v-bind:multiple="false"></FileInput>
<p>If story sequence is a video upload the video sequence.</p>
</div>
<div class="control">
<label>Story insights proofs</label>
<FileInput v-on:custom="handleStoryUpload" v-bind:id="'storyfile'" v-bind:label="'Upload story insights screenshots'" v-bind:accept="'image/jpeg,image/png,image/gif'" v-bind:isList="true" v-bind:icon="'fas fa-plus'" v-bind:multiple="true"></FileInput>
<FileInput v-on:custom="handleStoryUpload" v-bind:id="'storyProofs'" v-bind:label="'Upload story insights screenshots'" v-bind:accept="'image/jpeg,image/png,image/gif'" v-bind:isList="true" v-bind:icon="'fas fa-plus'" v-bind:multiple="true"></FileInput>
<p>If there are multiple images or videos for the story, we recommend creating one tracker per image or video.</p>
</div>
<div class="control">
Expand Down Expand Up @@ -147,6 +152,12 @@ export default {
loadCampaigns(){
this.$store.dispatch("fetchCampaigns").catch(e => {});
},
handleThumbnailUpload(files){
if(typeof files[0] === "undefined")
return;
this.story = files[0];
},
handleStoryUpload(files){
if(typeof files[0] === "undefined")
return;
Expand Down Expand Up @@ -212,27 +223,31 @@ export default {
});
// Dispatch the creation action
this.$store.dispatch("addNewStory", formData)
.then(response => {
this.createTrackerSuccess({
message: `Story ${response.content.name} created successfuly!`
});
this.$router.push({ name: 'stories' });
})
.catch(error => {
let errors = Object.values(error.response.data.errors);
if(typeof errors === "object" && errors.length > 0){
errors.forEach(element => {
if(typeof this.$route.params.uuid === "undefined" || this.$route.params.uuid === null){
this.$store.dispatch("addNewStory", formData)
.then(response => {
this.createTrackerSuccess({
message: `Story ${response.content.name} created successfuly!`
});
this.$router.push({ name: 'trackers' });
})
.catch(error => {
let errors = Object.values(error.response.data.errors);
if(typeof errors === "object" && errors.length > 0){
errors.forEach(element => {
this.showError({
message: element
});
});
}else{
this.showError({
message: element
message: error.response.data.message
});
});
}else{
this.showError({
message: error.response.data.message
});
}
});
}
});
}else{
// TODO: update exists story
}
}
},
mounted(){
Expand Down

0 comments on commit f84b492

Please sign in to comment.