(input: {
parentPageId: string;
destGroupId: string;
pageRelativeTitle: string;
pageAbsoluteTitle?: string;
createGroup?: {
groupName: string;
groupMemberName: string;
groupIsPublic: boolean;
groupPassword?: string;
};
})
| 12 | import { zxcvbn } from 'src/code/utils/zxcvbn'; |
| 13 | |
| 14 | export async function createPage(input: { |
| 15 | parentPageId: string; |
| 16 | destGroupId: string; |
| 17 | |
| 18 | pageRelativeTitle: string; |
| 19 | pageAbsoluteTitle?: string; |
| 20 | |
| 21 | createGroup?: { |
| 22 | groupName: string; |
| 23 | groupMemberName: string; |
| 24 | groupIsPublic: boolean; |
| 25 | groupPassword?: string; |
| 26 | }; |
| 27 | }) { |
| 28 | let groupContentKeyring: SymmetricKeyring | undefined; |
| 29 | |
| 30 | const pageId = nanoid(); |
| 31 | |
| 32 | let groupId; |
| 33 | |
| 34 | let groupCreation: Parameters< |
| 35 | typeof trpcClient.pages.create.mutate |
| 36 | >[0]['groupCreation']; |
| 37 | |
| 38 | if (input.createGroup != null) { |
| 39 | if (input.createGroup.groupName === '') { |
| 40 | throw new Error('Please enter a group name.'); |
| 41 | } |
| 42 | |
| 43 | if (input.createGroup.groupMemberName === '') { |
| 44 | throw new Error('Please enter an user alias.'); |
| 45 | } |
| 46 | |
| 47 | if ( |
| 48 | input.createGroup.groupPassword != null && |
| 49 | zxcvbn(input.createGroup.groupPassword).score <= 2 |
| 50 | ) { |
| 51 | await asyncDialog({ |
| 52 | title: 'Weak password', |
| 53 | html: true, |
| 54 | message: |
| 55 | 'Your password is relatively weak.<br/>Are you sure you want to continue?', |
| 56 | style: { width: 'max-content', padding: '4px 8px' }, |
| 57 | |
| 58 | focus: 'cancel', |
| 59 | |
| 60 | cancel: { label: 'No', flat: true, color: 'primary' }, |
| 61 | ok: { label: 'Yes', flat: true, color: 'negative' }, |
| 62 | }); |
| 63 | } |
| 64 | |
| 65 | const groupValues = await generateGroupValues({ |
| 66 | userKeyPair: internals.keyPair, |
| 67 | isPublic: input.createGroup.groupIsPublic, |
| 68 | password: |
| 69 | input.createGroup.groupPassword != null |
| 70 | ? input.createGroup.groupPassword |
| 71 | : undefined, |
nothing calls this directly
no test coverage detected