Closes #12, #227 and #58
This commit is contained in:
syuilo
2017-03-18 20:05:11 +09:00
parent 2496cece91
commit 45e8331e26
150 changed files with 610 additions and 609 deletions

View File

@@ -2,7 +2,7 @@
* API Request
*/
const CONFIG = require('./config');
import CONFIG from './config';
let spinner = null;
let pending = 0;
@@ -14,7 +14,7 @@ let pending = 0;
* @param {any} [data={}] Data
* @return {Promise<any>} Response
*/
module.exports = (i, endpoint, data = {}) => {
export default (i, endpoint, data = {}) => {
if (++pending === 1) {
spinner = document.createElement('div');
spinner.setAttribute('id', 'wait');

View File

@@ -1,6 +1,6 @@
module.exports = function(bytes) {
export default bytes => {
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
if (bytes == 0) return '0Byte';
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
return Math.round(bytes / Math.pow(1024, i), 2) + sizes[i];
}
};

View File

@@ -0,0 +1,14 @@
import CONFIG from './config';
export default function() {
fetch(CONFIG.apiUrl + '/meta', {
method: 'POST'
}).then(res => {
res.json().then(meta => {
if (meta.version != VERSION) {
localStorage.setItem('should-refresh', 'true');
alert('Misskeyの新しいバージョンがあります。ページを再度読み込みすると更新が適用されます。');
}
});
});
};

View File

@@ -9,7 +9,7 @@ const apiUrl = `${scheme}//api.${host}`;
const devUrl = `${scheme}//dev.${host}`;
const aboutUrl = `${scheme}//about.${host}`;
module.exports = {
export default {
host,
scheme,
url,

View File

@@ -1,8 +1,8 @@
module.exports = function(parent, child) {
export default (parent, child) => {
let node = child.parentNode;
while (node) {
if (node == parent) return true;
node = node.parentNode;
}
return false;
}
};

View File

@@ -1,7 +1,7 @@
/**
* Clipboardに値をコピー(TODO: 文字列以外も対応)
*/
module.exports = val => {
export default val => {
const form = document.createElement('textarea');
form.textContent = val;
document.body.appendChild(form);

View File

@@ -1,12 +1,12 @@
module.exports = date => {
export default date => {
if (typeof date == 'string') date = new Date(date);
return (
date.getFullYear() + '年' +
(date.getMonth() + 1) + '月' +
date.getFullYear() + '年' +
(date.getMonth() + 1) + '月' +
date.getDate() + '日' +
' ' +
date.getHours() + '時' +
date.getMinutes() + '分' +
date.getHours() + '時' +
date.getMinutes() + '分' +
' ' +
`(${['日', '月', '火', '水', '木', '金', '土'][date.getDay()]})`
);

View File

@@ -1,2 +1,2 @@
const gcd = (a, b) => !b ? a : gcd(b, a % b);
module.exports = gcd;
export default gcd;

View File

@@ -1,4 +1,4 @@
const uuid = require('./uuid.js');
import uuid from './uuid';
const home = {
left: [
@@ -17,7 +17,7 @@ const home = {
]
};
module.exports = () => {
export default () => {
const homeData = [];
home.left.forEach(widget => {

View File

@@ -1,3 +1 @@
module.exports = () => {
return '(=^・・^=)';
};
export default () => '(=^・・^=)';

View File

@@ -32,4 +32,4 @@ const summarize = post => {
return summary.trim();
};
module.exports = summarize;
export default summarize;

View File

@@ -1,20 +0,0 @@
const riot = require('riot');
module.exports = me => {
riot.mixin('i', {
init: function() {
this.I = me;
this.SIGNIN = me != null;
if (this.SIGNIN) {
this.on('mount', () => {
me.on('updated', this.update);
});
this.on('unmount', () => {
me.off('updated', this.update);
});
}
},
me: me
});
};

View File

@@ -1 +1 @@
module.exports = x => typeof x.then == 'function';
export default x => typeof x.then == 'function';

View File

@@ -6,7 +6,7 @@ NProgress.configure({
const root = document.getElementsByTagName('html')[0];
module.exports = {
export default {
start: () => {
root.classList.add('progress');
NProgress.start();

View File

@@ -1,6 +1,6 @@
const ReconnectingWebSocket = require('reconnecting-websocket');
const riot = require('riot');
const CONFIG = require('./config');
import * as riot from 'riot';
import CONFIG from './config';
class Connection {
constructor(me, otherparty) {
@@ -40,4 +40,4 @@ class Connection {
}
}
module.exports = Connection;
export default Connection;

View File

@@ -1,6 +1,6 @@
const CONFIG = require('./config');
import CONFIG from './config';
module.exports = () => {
export default () => {
localStorage.removeItem('me');
document.cookie = `i=; domain=.${CONFIG.host}; expires=Thu, 01 Jan 1970 00:00:01 GMT;`;
location.href = '/';

View File

@@ -1,40 +1,53 @@
const ReconnectingWebSocket = require('reconnecting-websocket');
const riot = require('riot');
const CONFIG = require('./config');
import * as riot from 'riot';
import CONFIG from './config';
module.exports = me => {
let state = 'initializing';
const stateEv = riot.observable();
const event = riot.observable();
const host = CONFIG.apiUrl.replace('http', 'ws');
const socket = new ReconnectingWebSocket(`${host}?i=${me.token}`);
class Connection {
constructor(me) {
// BIND -----------------------------------
this.onOpen = this.onOpen.bind(this);
this.onClose = this.onClose.bind(this);
this.onMessage = this.onMessage.bind(this);
this.close = this.close.bind(this);
// ----------------------------------------
socket.onopen = () => {
state = 'connected';
stateEv.trigger('connected');
};
this.state = 'initializing';
this.stateEv = riot.observable();
this.event = riot.observable();
this.me = me;
socket.onclose = () => {
state = 'reconnecting';
stateEv.trigger('closed');
};
const host = CONFIG.apiUrl.replace('http', 'ws');
this.socket = new ReconnectingWebSocket(`${host}?i=${me.token}`);
this.socket.addEventListener('open', this.onOpen);
this.socket.addEventListener('close', this.onClose);
this.socket.addEventListener('message', this.onMessage);
socket.onmessage = message => {
this.event.on('i_updated', me.update);
}
onOpen() {
this.state = 'connected';
this.stateEv.trigger('connected');
}
onClose() {
this.state = 'reconnecting';
this.stateEv.trigger('closed');
}
onMessage(message) {
try {
const msg = JSON.parse(message.data);
if (msg.type) {
event.trigger(msg.type, msg.body);
}
} catch (e) {
if (msg.type) this.event.trigger(msg.type, msg.body);
} catch(e) {
// noop
}
};
}
event.on('i_updated', me.update);
close() {
this.socket.removeEventListener('open', this.onOpen);
this.socket.removeEventListener('message', this.onMessage);
}
}
return {
stateEv: stateEv,
getState: () => state,
event: event
};
};
export default Connection;

View File

@@ -1,13 +1,13 @@
const riot = require('riot');
import * as riot from 'riot';
//const emojinize = require('emojinize');
const CONFIG = require('./config');
import CONFIG from './config';
const escape = text =>
text
.replace(/>/g, '&gt;')
.replace(/</g, '&lt;');
module.exports = (tokens, shouldBreak) => {
export default (tokens, shouldBreak) => {
if (shouldBreak == null) {
shouldBreak = true;
}
@@ -20,21 +20,21 @@ module.exports = (tokens, shouldBreak) => {
return escape(token.content)
.replace(/(\r\n|\n|\r)/g, shouldBreak ? '<br>' : ' ');
case 'bold':
return '<strong>' + escape(token.bold) + '</strong>';
return `<strong>${escape(token.bold)}</strong>`;
case 'url':
return '<mk-url href="' + escape(token.content) + '" target="_blank"></mk-url>';
return `<mk-url href="${escape(token.content)}" target="_blank"></mk-url>`;
case 'link':
return '<a class="link" href="' + escape(token.url) + '" target="_blank">' + escape(token.title) + '</a>';
return `<a class="link" href="${escape(token.url)}" target="_blank" title="${escape(token.url)}">${escape(token.title)}</a>`;
case 'mention':
return '<a href="' + CONFIG.url + '/' + escape(token.username) + '" target="_blank" data-user-preview="' + token.content + '" ' + (me && me.username == token.username ? 'data-is-me' : '') + '>' + token.content + '</a>';
return `<a href="${CONFIG.url + '/' + escape(token.username)}" target="_blank" data-user-preview="${token.content}" ${me && me.username == token.username ? 'data-is-me' : ''}>${token.content}</a>`;
case 'hashtag': // TODO
return '<a>' + escape(token.content) + '</a>';
return `<a>${escape(token.content)}</a>`;
case 'code':
return '<pre><code>' + token.html + '</code></pre>';
return `<pre><code>${token.html}</code></pre>`;
case 'inline-code':
return '<code>' + token.html + '</code>';
return `<code>${token.html}</code>`;
case 'emoji':
return '<i>' + token.content + '</i>';
return `<i>${token.content}</i>`;
//return emojinize.encode(token.content)
}
}).join('');

View File

@@ -1,12 +1,12 @@
module.exports = function () {
export default () => {
var uuid = '', i, random;
for (i = 0; i < 32; i++) {
random = Math.random() * 16 | 0;
if (i == 8 || i == 12 || i == 16 || i == 20) {
uuid += '-'
uuid += '-';
}
uuid += (i == 12 ? 4 : (i == 16 ? (random & 3 | 8) : random)).toString(16);
}
return uuid;
}
};