This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import App, { Container } from "next/app"; | |
import { Provider } from "react-redux"; | |
import MainLayout from "../components/Layouts/MainLayout"; | |
class MyApp extends App { | |
static async getInitialProps({ Component, ctx }) { | |
return {} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as routing from "workbox-routing"; | |
import * as core from "workbox-core"; | |
import * as strategies from "workbox-strategies"; | |
import * as expiration from "workbox-cache-expiration"; | |
import * as cacheableResponse from "workbox-cacheable-response"; | |
self.addEventListener("sync", function (event) { | |
console.log("Event from sw: ", event); | |
}); | |
self.addEventListener("install", function () { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def send_email(email, csv_path, zip_path) do | |
attachments = if !is_nil(zip_path) do | |
[Bamboo.Attachment.new(zip_path)] | |
else | |
[] | |
end | |
attachments = [Bamboo.Attachment.new(csv_path) | attachments] | |
new_email(attachments: attachments) | |
|> subject("Your download is here") | |
|> from("support@example.com") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_zip(path) do | |
old_path = File.cwd! | |
File.cd! path | |
:zip.create("images.zip", ['images'], [{:cwd, path}]) | |
File.cd! old_path | |
path<>"/images.zip" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def export_images_to_zip(data, path) do | |
images_to_download = Enum.map(data, fn datum -> | |
%{url: datum.image, name: datum.name} | |
end) | |
case images_to_download do | |
[] -> nil | |
list -> | |
zip_path = path<>"/images" | |
:ok = File.mkdir_p!(zip_path) | |
download_images_in_batch(list, zip_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def export_to_csv(data, path) do | |
file_path = path<>"/export.csv" | |
result = Enum.map(data, fn item -> | |
"#{item.name}\",#{item.email},\"#{item.image}" | |
end) | |
result = ["Name,Email,Image Url" | result] | |
File.write!(file_path, Enum.join(result, "\r\n"), [:utf8]) | |
file_path | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def export_download_zip_email(data, email) do | |
tmp_folder_name = "users_"<>Random.random_string(8) | |
path = File.cwd!<>"/tmp/"<>tmp_folder_name | |
:ok = File.mkdir_p!(path) | |
csv_path = export_to_csv(data, path) | |
download_images(data, path) | |
zip_path = create_zip(data, path) | |
send_email(email, csv_path, zip_path) | |
File.rm_rf path | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@agent :export_email_state | |
def start_link() do | |
GenServer.start_link(__MODULE__, %{}, [name: __MODULE__]) | |
Agent.start_link(fn -> Map.new end, name: @agent) | |
end | |
def handle_cast({:export_email, {data, email}}, state) do | |
key = email | |
job_status = Agent.get(@agent, fn agent_state -> Map.get(agent_state, key) end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
%Example.User{ | |
name: "John", | |
email: "john@example.com", | |
image: "https://images.example.com/uploads/eaa88003-fa4e-4ba7-afb1-787dcdea72af.jpg" | |
inserted_at: ~N[2017-10-19 21:22:45.683899], | |
updated_at: ~N[2017-11-02 14:04:55.616742] | |
} | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Example.AdminController do | |
use Example, :controller | |
def export(conn, %{"email" => email}) do | |
Example.User.get_dump() | |
|> Example.Export.export_and_email(email) | |
json(conn, %{ | |
success: true, | |
message: "Your request is accepted. Data will be emailed shortly" | |
}) |
NewerOlder