Skip to content

Commit

Permalink
Add a name test in storeAvatar
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-Works committed Apr 26, 2019
1 parent 0777769 commit a49b933
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 10 deletions.
11 changes: 6 additions & 5 deletions src/background-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ if (GetContext() === 'background') {
require('./extension/background-script')
}

const old = console.log
console.log = (...args: any[]) => {
if (args[0] === 'secp256k1') return // drop the annoying log
return old(...args)
}
console.log = new Proxy(console.log, {
apply(target, _, args) {
if (args[0] === 'secp256k1') return
return target(...args)
},
})
4 changes: 0 additions & 4 deletions src/components/Welcomes/1a4.auto.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import * as React from 'react'
import Paper from '@material-ui/core/Paper/Paper'
import Typography from '@material-ui/core/Typography/Typography'
import { withStylesTyped } from '../../utils/theme'
import createStyles from '@material-ui/core/styles/createStyles'
import Button from '@material-ui/core/Button/Button'
import classNames from 'classnames'
import Radio from '@material-ui/core/Radio/Radio'
import { FlexBox } from '../../utils/components/Flex'
import FormControl from '@material-ui/core/FormControl/FormControl'
import FormLabel from '@material-ui/core/FormLabel/FormLabel'
import RadioGroup from '@material-ui/core/RadioGroup/RadioGroup'
import FormControlLabel from '@material-ui/core/FormControlLabel/FormControlLabel'

Expand Down
1 change: 1 addition & 0 deletions src/extension/background-script/PeopleService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { uploadProvePostUrl } from '../../key-management/people-gun'
import { storeLocalKey } from '../../key-management/local-db'

OnlyRunInContext('background', 'FriendService')

export interface Person {
username: string
nickname?: string
Expand Down
2 changes: 1 addition & 1 deletion src/extension/content-script/rpc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AsyncCall, MessageCenter } from '@holoflows/kit/es'
import { AsyncCall } from '@holoflows/kit/es'
import { Background } from '../background-script/BackgroundService'
import { BackgroundName, CryptoName, FriendServiceName } from '../../utils/constants'
import { Encrypt } from '../background-script/CryptoService'
Expand Down
2 changes: 2 additions & 0 deletions src/key-management/avatar-db.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Entity, Index, Db } from 'typed-db'
import { buildQuery } from '../utils/utils'
import { regularUsername } from '../utils/type-transform/Username'

@Entity()
class AvatarRecord {
Expand All @@ -23,6 +24,7 @@ export async function queryNickname(username: string): Promise<string | undefine
return result.nickname
}
export async function storeAvatar(username: string, nickname: string, avatar: ArrayBuffer | string) {
if (regularUsername(username) === null) return
const last = await query(t => t.get(username))
if (last && (Date.now() - last.lastUpdateTime.getTime()) / 1000 / 60 / 60 / 24 < 14) {
return
Expand Down
14 changes: 14 additions & 0 deletions src/utils/type-transform/Username.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @see https://www.facebook.com/help/105399436216001#What-are-the-guidelines-around-creating-a-custom-username?
* @unstable
* ! Start to use this in a breaking change!
*/
export function regularUsername(name: string) {
// Avoid common mistake
if (name === 'photo.php') return null
const n = name.toLowerCase().replace(/\./g, '')
if (n.match(/^[a-z0-9]{5,}$/)) {
return n
}
return null
}

0 comments on commit a49b933

Please sign in to comment.