chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1 @@
|
||||
export const referer = 'https://fiora.suisuijiang.com/';
|
||||
@@ -0,0 +1,79 @@
|
||||
// function convertRobot10Message(message) {
|
||||
// if (message.from._id === '5adad39555703565e7903f79') {
|
||||
// try {
|
||||
// const parseMessage = JSON.parse(message.content);
|
||||
// message.from.tag = parseMessage.source;
|
||||
// message.from.avatar = parseMessage.avatar;
|
||||
// message.from.username = parseMessage.username;
|
||||
// message.type = parseMessage.type;
|
||||
// message.content = parseMessage.content;
|
||||
// } catch (err) {
|
||||
// console.warn('解析robot10消息失败', err);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
import { Message } from '../types/redux';
|
||||
|
||||
const WuZeiNiangImage = require('../assets/images/wuzeiniang.gif');
|
||||
|
||||
function convertSystemMessage(message: Message) {
|
||||
if (message.type === 'system') {
|
||||
message.from._id = 'system';
|
||||
message.from.originUsername = message.from.username;
|
||||
message.from.username = '乌贼娘殿下';
|
||||
message.from.avatar = WuZeiNiangImage;
|
||||
message.from.tag = 'system';
|
||||
|
||||
let content = null;
|
||||
try {
|
||||
content = JSON.parse(message.content);
|
||||
} catch {
|
||||
content = {
|
||||
command: 'parse-error',
|
||||
};
|
||||
}
|
||||
switch (content?.command) {
|
||||
case 'roll': {
|
||||
message.content = `掷出了${content.value}点 (上限${content.top}点)`;
|
||||
break;
|
||||
}
|
||||
case 'rps': {
|
||||
message.content = `使出了 ${content.value}`;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
message.content = '不支持的指令';
|
||||
}
|
||||
}
|
||||
} else if (message.deleted) {
|
||||
message.type = 'system';
|
||||
message.from._id = 'system';
|
||||
message.from.originUsername = message.from.username;
|
||||
message.from.username = '乌贼娘殿下';
|
||||
message.from.avatar = WuZeiNiangImage;
|
||||
message.from.tag = 'system';
|
||||
message.content = `撤回了消息`;
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理文本消息的html转义字符
|
||||
* @param {Object} message 消息
|
||||
*/
|
||||
function convertMessageHtml(message: Message) {
|
||||
if (message.type === 'text') {
|
||||
message.content = message.content
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>');
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
export default function convertMessage(message: Message) {
|
||||
convertSystemMessage(message);
|
||||
convertMessageHtml(message);
|
||||
return message;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
export default {
|
||||
default: [
|
||||
'呵呵',
|
||||
'哈哈',
|
||||
'吐舌',
|
||||
'啊',
|
||||
'酷',
|
||||
'怒',
|
||||
'开心',
|
||||
'汗',
|
||||
'泪',
|
||||
'黑线',
|
||||
'鄙视',
|
||||
'不高兴',
|
||||
'真棒',
|
||||
'钱',
|
||||
'疑问',
|
||||
'阴险',
|
||||
'吐',
|
||||
'咦',
|
||||
'委屈',
|
||||
'花心',
|
||||
'呼',
|
||||
'笑眼',
|
||||
'冷',
|
||||
'太开心',
|
||||
'滑稽',
|
||||
'勉强',
|
||||
'狂汗',
|
||||
'乖',
|
||||
'睡觉',
|
||||
'惊哭',
|
||||
'升起',
|
||||
'惊讶',
|
||||
'喷',
|
||||
'爱心',
|
||||
'心碎',
|
||||
'玫瑰',
|
||||
'礼物',
|
||||
'星星月亮',
|
||||
'太阳',
|
||||
'音乐',
|
||||
'灯泡',
|
||||
'蛋糕',
|
||||
'彩虹',
|
||||
'钱币',
|
||||
'咖啡',
|
||||
'haha',
|
||||
'胜利',
|
||||
'大拇指',
|
||||
'弱',
|
||||
'ok',
|
||||
],
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
import Toast from '../components/Toast';
|
||||
import socket from '../socket';
|
||||
|
||||
export default function fetch<T = any>(
|
||||
event: string,
|
||||
data: any = {},
|
||||
{ toast = true } = {},
|
||||
): Promise<[string | null, T | null]> {
|
||||
return new Promise((resolve) => {
|
||||
socket.emit(event, data, (res: any) => {
|
||||
if (typeof res === 'string') {
|
||||
if (toast) {
|
||||
Toast.danger(res);
|
||||
}
|
||||
resolve([res, null]);
|
||||
} else {
|
||||
resolve([null, res]);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
export default function getFriendId(userId1: string, userId2: string) {
|
||||
if (userId1 < userId2) {
|
||||
return userId1 + userId2;
|
||||
}
|
||||
return userId2 + userId1;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import randomColor from 'randomcolor';
|
||||
|
||||
type ColorMode = 'dark' | 'bright' | 'light' | 'random';
|
||||
|
||||
/**
|
||||
* 获取随机颜色, 刷新页面不变
|
||||
* @param seed when passed will cause randomColor to return the same color each time
|
||||
*/
|
||||
export function getRandomColor(seed: string, luminosity: ColorMode = 'dark') {
|
||||
return randomColor({
|
||||
luminosity,
|
||||
seed,
|
||||
});
|
||||
}
|
||||
|
||||
type Cache = {
|
||||
[key: string]: string;
|
||||
};
|
||||
|
||||
const cache: Cache = {};
|
||||
|
||||
/**
|
||||
* 获取随机颜色, 刷新页面后重新随机
|
||||
* @param seed 随机种子
|
||||
* @param luminosity 亮度
|
||||
*/
|
||||
export function getPerRandomColor(
|
||||
seed: string,
|
||||
luminosity: ColorMode = 'dark',
|
||||
) {
|
||||
if (cache[seed]) {
|
||||
return cache[seed];
|
||||
}
|
||||
cache[seed] = randomColor({ luminosity });
|
||||
return cache[seed];
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Friend, Group, Linkman } from '../types/redux';
|
||||
|
||||
export function formatLinkmanName(linkman: Linkman) {
|
||||
if (linkman!.type === 'group' && (linkman as Group).members.length > 0) {
|
||||
return `${(linkman as Group).name} (${
|
||||
(linkman as Group).members.length
|
||||
})`;
|
||||
}
|
||||
if (
|
||||
linkman!.type !== 'group' &&
|
||||
(linkman as Friend).isOnline !== undefined
|
||||
) {
|
||||
return `${(linkman as Friend).name} (${
|
||||
(linkman as Friend).isOnline ? '在线' : '离线'
|
||||
})`;
|
||||
}
|
||||
return linkman.name;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { Platform } from 'react-native';
|
||||
import Constants from 'expo-constants';
|
||||
// eslint-disable-next-line import/extensions
|
||||
import packageInfo from '../../app.json';
|
||||
|
||||
const os = Platform.OS === 'ios' ? 'iOS' : 'Android';
|
||||
|
||||
export const isiOS = Platform.OS === 'ios';
|
||||
export const isAndroid = Platform.OS === 'android';
|
||||
|
||||
export default {
|
||||
os,
|
||||
browser: 'App',
|
||||
environment: `App ${
|
||||
process.env.NODE_ENV === 'development'
|
||||
? '开发版'
|
||||
: packageInfo.expo.version
|
||||
} on ${os} ${
|
||||
isiOS ? Constants.platform?.ios?.systemVersion : Constants.systemVersion
|
||||
} ${isiOS ? Constants.platform?.ios?.model : ''}`,
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
|
||||
export async function getStorageValue(key: string) {
|
||||
return AsyncStorage.getItem(key);
|
||||
}
|
||||
|
||||
export async function setStorageValue(key: string, value: string) {
|
||||
return AsyncStorage.setItem(key, value);
|
||||
}
|
||||
|
||||
export async function removeStorageValue(key: string) {
|
||||
return AsyncStorage.removeItem(key);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
export default {
|
||||
isToday(time1: Date, time2: Date) {
|
||||
return (
|
||||
time1.getFullYear() === time2.getFullYear() &&
|
||||
time1.getMonth() === time2.getMonth() &&
|
||||
time1.getDate() === time2.getDate()
|
||||
);
|
||||
},
|
||||
isYesterday(time1: Date, time2: Date) {
|
||||
const prevDate = new Date(time1);
|
||||
prevDate.setDate(time1.getDate() - 1);
|
||||
return (
|
||||
prevDate.getFullYear() === time2.getFullYear() &&
|
||||
prevDate.getMonth() === time2.getMonth() &&
|
||||
prevDate.getDate() === time2.getDate()
|
||||
);
|
||||
},
|
||||
isSameYear(time1: Date, time2: Date) {
|
||||
return time1.getFullYear() === time2.getFullYear();
|
||||
},
|
||||
getHourMinute(time: Date) {
|
||||
const hours = time.getHours();
|
||||
const minutes = time.getMinutes();
|
||||
return `${hours < 10 ? `0${hours}` : hours}:${
|
||||
minutes < 10 ? `0${minutes}` : minutes
|
||||
}`;
|
||||
},
|
||||
getMonthDate(time: Date) {
|
||||
return `${time.getMonth() + 1}/${time.getDate()}`;
|
||||
},
|
||||
getYearMonthDate(time: Date) {
|
||||
return `${time.getFullYear()}/${time.getMonth() + 1}/${time.getDate()}`;
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,41 @@
|
||||
import fetch from './fetch';
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
* @param blob 文件blob数据
|
||||
* @param fileName 文件名
|
||||
*/
|
||||
export default async function uploadFile(
|
||||
blob: Blob | string,
|
||||
fileName: string,
|
||||
isBase64 = false,
|
||||
): Promise<string> {
|
||||
const [uploadErr, result] = await fetch('uploadFile', {
|
||||
file: blob,
|
||||
fileName,
|
||||
isBase64,
|
||||
});
|
||||
if (uploadErr) {
|
||||
throw Error(`上传图片失败::${uploadErr}`);
|
||||
}
|
||||
return result.url;
|
||||
}
|
||||
|
||||
export function getOSSFileUrl(url: string | number = '', process = '') {
|
||||
if (typeof url === 'number') {
|
||||
return url;
|
||||
}
|
||||
const [rawUrl = '', extraPrams = ''] = url.split('?');
|
||||
if (/^\/\/cdn\.suisuijiang\.com/.test(rawUrl)) {
|
||||
return `https:${rawUrl}?x-oss-process=${process}${
|
||||
extraPrams ? `&${extraPrams}` : ''
|
||||
}`;
|
||||
}
|
||||
if (url.startsWith('//')) {
|
||||
return `https:${url}`;
|
||||
}
|
||||
if (url.startsWith('/')) {
|
||||
return `https://fiora.suisuijiang.com${url}`;
|
||||
}
|
||||
return `${url}`;
|
||||
}
|
||||
Reference in New Issue
Block a user