Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[add] Changing communication method. #84

Merged
merged 1 commit into from
Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions aicon/frontend/static/js/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,6 @@ function target_handleFiles(files) {
secret_reader.onload = function () {
secret_img.src = secret_reader.result;
target_img = secret_img.src.replace(/data:.*\/.*;base64,/, '');
// console.log(secret_img.src.replace(/data:.*\/.*;base64,/, ''))
}
secret_reader.readAsDataURL(target_file);

Expand All @@ -385,7 +384,6 @@ function target_handleFiles(files) {
let reader = new FileReader();
reader.onload = function () {
img.src = reader.result;
// console.log(img.src)
$('#target_preview_field').append(img);
}
reader.readAsDataURL(target_file);
Expand Down Expand Up @@ -541,10 +539,6 @@ function wait_display() {
function sort_order(priority, model_status) {
const color_list_ = ['rgba(100, 190, 228, 1)', 'rgba(80, 180, 228, 1)', 'rgba(55, 170, 228, 1)', 'rgba(25, 160, 228, 1)', 'rgba(4, 155, 228, 1)'];
priority = priority > 5 ? 5 : priority;
console.log('priority')
console.log(priority)
// console.log("model_status")
// console.log(model_status)
for (let i = 1; i < 6; i++) {
$('#waiter_' + i).css('color', color_list_[i-1]);
}
Expand Down Expand Up @@ -626,15 +620,11 @@ function communicate(s_data) {
if (r_data['current_iter'] === null) {
r_data['current_iter'] = 0;
}
console.log(r_data['current_iter'])
console.log(tmp_data['total_iter'])
console.log((100 * r_data['current_iter']/tmp_data['total_iter']))
$('.determinate').attr('style', 'width:' + (100 * r_data['current_iter']/tmp_data['total_iter']) + '%');

// 生成画像の表示
if (!(r_data["img_path"] === null)) {
let img_path = r_data["img_path"].replace('..', 'http://' + $('#communication_partner').val() + ':5050');
console.log(img_path)
$('#result_img').attr("src", img_path).on("load", function () {
$('#result_img').fadeIn();
});
Expand Down Expand Up @@ -678,35 +668,45 @@ function wait(msec) {
return objDef.promise();
}

// 画像と動画に関する関数です
$('.save_content').click(function() {
$('#' + this.id)
let link = document.getElementById("download");
// link.href =
});
// // 画像と動画に関する関数です
// $('.save_content').click(function() {
// $('#' + this.id)
// let link = document.getElementById("download");
// // link.href =
// });


// Twitterへの変更じ関する関数です
$('.twitter').click(function () {
let twitter_button = this.id;
let path = "";
let mode = "";
if (twitter_button === "tweet") {
path = $('#download_mp4').attr("href");
mode = "tweet";
}
else if (twitter_button === "change_icon") {
path = $('#download_img').attr("href");
mode = "icon"
}
// 送信するデータ
twitter_data = {
path: path,
mode: mode
};
let twitter_send_data = JSON.stringify(twitter_data);
// console.log(twitter_data)
// console.log(twitter_send_data)
$.ajax({
url: "http://" + $('#communication_partner').val() + ":5050/twitter/auth",
method: "POST", //HTTPメソッドの種別
data: twitter_send_data,
dataType: "json", //データの受信形式
timeout: 10000, //タイムアウト値(ミリ秒)
async: false, //同期通信 false:同期 true:非同期
contentType: "application/json; charset=utf-8",
})
.done(function (r_data, textStatus, xhr) {
if (twitter_button === "tweet") {
$.cookie("mode", "tweet");
}
else if (twitter_button === "change_icon") {
$.cookie("mode", "icon");
};
console.log(twitter_button)
$.cookie("img_path", $("#" + twitter_button).attr("href"));
console.log(r_data["authorization_url"])
window.open(r_data["authorization_url"]);
})
.fail(function (r_data, textStatus, xhr) {
Expand Down
114 changes: 114 additions & 0 deletions aicon/frontend/static/js/jquery.cookie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*!
* jQuery Cookie Plugin v1.4.1
* https://github.com/carhartl/jquery-cookie
*
* Copyright 2006, 2014 Klaus Hartl
* Released under the MIT license
*/
(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD (Register as an anonymous module)
define(['jquery'], factory);
} else if (typeof exports === 'object') {
// Node/CommonJS
module.exports = factory(require('jquery'));
} else {
// Browser globals
factory(jQuery);
}
}(function ($) {

var pluses = /\+/g;

function encode(s) {
return config.raw ? s : encodeURIComponent(s);
}

function decode(s) {
return config.raw ? s : decodeURIComponent(s);
}

function stringifyCookieValue(value) {
return encode(config.json ? JSON.stringify(value) : String(value));
}

function parseCookieValue(s) {
if (s.indexOf('"') === 0) {
// This is a quoted cookie as according to RFC2068, unescape...
s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
}

try {
// Replace server-side written pluses with spaces.
// If we can't decode the cookie, ignore it, it's unusable.
// If we can't parse the cookie, ignore it, it's unusable.
s = decodeURIComponent(s.replace(pluses, ' '));
return config.json ? JSON.parse(s) : s;
} catch(e) {}
}

function read(s, converter) {
var value = config.raw ? s : parseCookieValue(s);
return $.isFunction(converter) ? converter(value) : value;
}

var config = $.cookie = function (key, value, options) {

// Write

if (arguments.length > 1 && !$.isFunction(value)) {
options = $.extend({}, config.defaults, options);

if (typeof options.expires === 'number') {
var days = options.expires, t = options.expires = new Date();
t.setMilliseconds(t.getMilliseconds() + days * 864e+5);
}

return (document.cookie = [
encode(key), '=', stringifyCookieValue(value),
options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
options.path ? '; path=' + options.path : '',
options.domain ? '; domain=' + options.domain : '',
options.secure ? '; secure' : ''
].join(''));
}

// Read

var result = key ? undefined : {},
// To prevent the for loop in the first place assign an empty array
// in case there are no cookies at all. Also prevents odd result when
// calling $.cookie().
cookies = document.cookie ? document.cookie.split('; ') : [],
i = 0,
l = cookies.length;

for (; i < l; i++) {
var parts = cookies[i].split('='),
name = decode(parts.shift()),
cookie = parts.join('=');

if (key === name) {
// If second argument (value) is a function it's a converter...
result = read(cookie, value);
break;
}

// Prevent storing a cookie that we couldn't decode.
if (!key && (cookie = read(cookie)) !== undefined) {
result[name] = cookie;
}
}

return result;
};

config.defaults = {};

$.removeCookie = function (key, options) {
// Must not alter options, thus extending a fresh object...
$.cookie(key, '', $.extend({}, options, { expires: -1 }));
return !$.cookie(key);
};

}));
2 changes: 2 additions & 0 deletions aicon/frontend/static/js/jquery.min.js

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions aicon/frontend/templates/authentication.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html>

<body>

<!--入力フォーム-->
<input type="text" id="content">
<!--ご自身のTwitterアカウントへ行きます-->
<button id="twitter" class="btn" type="button">Tweet</button>

<script>
// twitter共有機能
document.getElementById("twitter").addEventListener('click', function (event) {
event.preventDefault();
var left = Math.round(window.screen.width / 2 - 275);
var top = (window.screen.height > 420) ? Math.round(window.screen.height / 2 - 210) : 0;
window.open(
"https://twitter.com/intent/tweet?text=" + encodeURIComponent(document.getElementById(
"content").value),
null,
"scrollbars=yes,resizable=yes,toolbar=no,location=yes,width=550,height=420,left=" + left +
",top=" + top);
});
</script>
</body>

</html>
18 changes: 18 additions & 0 deletions aicon/frontend/templates/twitter-callback.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="">
<script src="{{ url_for('static', filename='js/jquery.min.js') }}"></script>
<script>
$(function () {
console.log(location.search);
console.log("twitter-callback");
console.log("twitter-callback");
console.log("twitter-callback");
console.log("twitter-callback");
console.log("twitter/send" + location.search);

// sleep(5000000);

window.location.href = "send" + location.search;
});
</script>
</html>
11 changes: 11 additions & 0 deletions aicon/frontend/templates/twitter-send.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="">
<script src="{{ url_for('static', filename='js/jquery.min.js') }}"></script>
<script>
$(function () {
console.log("twitter-send");
window.close();
});
</script>

</html>