strictNullChecks (#4666)

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip
This commit is contained in:
syuilo
2019-04-13 01:43:22 +09:00
committed by GitHub
parent 4ee40c3345
commit 987168b863
214 changed files with 939 additions and 785 deletions

View File

@@ -34,14 +34,14 @@ async function genVars(lang: string): Promise<{ [key: string]: any }> {
const docs = glob.sync(`src/docs/**/*.${lang}.md`, { cwd });
vars['docs'] = {};
for (const x of docs) {
const [, name] = x.match(/docs\/(.+?)\.(.+?)\.md$/);
const [, name] = x.match(/docs\/(.+?)\.(.+?)\.md$/)!;
if (vars['docs'][name] == null) {
vars['docs'][name] = {
name,
title: {}
};
}
vars['docs'][name]['title'][lang] = fs.readFileSync(cwd + x, 'utf-8').match(/^# (.+?)\r?\n/)[1];
vars['docs'][name]['title'][lang] = fs.readFileSync(cwd + x, 'utf-8').match(/^# (.+?)\r?\n/)![1];
}
vars['kebab'] = (string: string) => string.replace(/([a-z])([A-Z])/g, '$1-$2').replace(/\s+/g, '-').toLowerCase();
@@ -97,7 +97,7 @@ router.get('/*/*', async ctx => {
await ctx.render('../../../../src/docs/article', Object.assign({
id: doc,
html: conv.makeHtml(md),
title: md.match(/^# (.+?)\r?\n/)[1],
title: md.match(/^# (.+?)\r?\n/)![1],
src: `https://github.com/syuilo/misskey/tree/master/src/docs/${doc}.${lang}.md`
}, await genVars(lang)));

View File

@@ -3,6 +3,7 @@ import config from '../../config';
import { User } from '../../models/entities/user';
import { Notes, DriveFiles, UserProfiles } from '../../models';
import { In } from 'typeorm';
import { ensure } from '../../prelude/ensure';
export default async function(user: User) {
const author: Author = {
@@ -10,7 +11,7 @@ export default async function(user: User) {
name: user.name || user.username
};
const profile = await UserProfiles.findOne({ userId: user.id });
const profile = await UserProfiles.findOne({ userId: user.id }).then(ensure);
const notes = await Notes.find({
where: {
@@ -47,9 +48,9 @@ export default async function(user: User) {
title: `New note by ${author.name}`,
link: `${config.url}/notes/${note.id}`,
date: note.createdAt,
description: note.cw,
content: note.text,
image: file ? DriveFiles.getPublicUrl(file) : null
description: note.cw || undefined,
content: note.text || undefined,
image: file ? DriveFiles.getPublicUrl(file) : undefined
});
}

View File

@@ -19,6 +19,7 @@ import config from '../../config';
import { Users, Notes, Emojis, UserProfiles } from '../../models';
import parseAcct from '../../misc/acct/parse';
import getNoteSummary from '../../misc/get-note-summary';
import { ensure } from '../../prelude/ensure';
const client = `${__dirname}/../../client/`;
@@ -149,11 +150,9 @@ router.get('/@:user', async (ctx, next) => {
usernameLower: username.toLowerCase(),
host
});
const profile = await UserProfiles.findOne({
userId: user.id
});
if (user != null) {
const profile = await UserProfiles.findOne(user.id).then(ensure);
const meta = await fetchMeta();
await ctx.render('user', {
user, profile,

View File

@@ -43,7 +43,7 @@ module.exports = async (ctx: Koa.BaseContext) => {
}
};
function wrap(url: string): string {
function wrap(url?: string): string | null {
return url != null
? url.match(/^https?:\/\//)
? `${config.url}/proxy/preview.jpg?${query({