feat: use SafeInt replace Float (#5613)

This commit is contained in:
DarkSky
2024-01-17 12:36:21 +00:00
parent b9f20877d0
commit ee8ec47a4f
11 changed files with 40 additions and 18 deletions

View File

@@ -63,6 +63,7 @@
"file-type": "^19.0.0",
"get-stream": "^8.0.1",
"graphql": "^16.8.1",
"graphql-scalars": "^1.22.4",
"graphql-type-json": "^0.3.2",
"graphql-upload": "^16.0.2",
"ioredis": "^5.3.2",

View File

@@ -1,5 +1,6 @@
import { createUnionType, Field, Float, ID, ObjectType } from '@nestjs/graphql';
import { createUnionType, Field, ID, ObjectType } from '@nestjs/graphql';
import type { User } from '@prisma/client';
import { SafeIntResolver } from 'graphql-scalars';
@ObjectType('UserQuotaHumanReadable')
export class UserQuotaHumanReadableType {
@@ -24,13 +25,13 @@ export class UserQuotaType {
@Field({ name: 'name' })
name!: string;
@Field(() => Float, { name: 'blobLimit' })
@Field(() => SafeIntResolver, { name: 'blobLimit' })
blobLimit!: number;
@Field(() => Float, { name: 'storageQuota' })
@Field(() => SafeIntResolver, { name: 'storageQuota' })
storageQuota!: number;
@Field(() => Float, { name: 'historyPeriod' })
@Field(() => SafeIntResolver, { name: 'historyPeriod' })
historyPeriod!: number;
@Field({ name: 'memberLimit' })

View File

@@ -1,7 +1,6 @@
import { HttpStatus, Logger, UseGuards } from '@nestjs/common';
import {
Args,
Float,
Int,
Mutation,
Parent,
@@ -10,6 +9,7 @@ import {
Resolver,
} from '@nestjs/graphql';
import { GraphQLError } from 'graphql';
import { SafeIntResolver } from 'graphql-scalars';
import GraphQLUpload from 'graphql-upload/GraphQLUpload.mjs';
import {
@@ -100,7 +100,7 @@ export class WorkspaceBlobResolver {
async checkBlobSize(
@CurrentUser() user: UserType,
@Args('workspaceId') workspaceId: string,
@Args('size', { type: () => Float }) blobSize: number
@Args('size', { type: () => SafeIntResolver }) blobSize: number
) {
const canWrite = await this.permissions.tryCheckWorkspace(
workspaceId,

View File

@@ -1,6 +1,5 @@
import {
Field,
Float,
ID,
InputType,
ObjectType,
@@ -10,6 +9,7 @@ import {
registerEnumType,
} from '@nestjs/graphql';
import type { Workspace } from '@prisma/client';
import { SafeIntResolver } from 'graphql-scalars';
import { UserType } from '../users/types';
@@ -78,7 +78,7 @@ export class InvitationWorkspaceType {
@ObjectType()
export class WorkspaceBlobSizes {
@Field(() => Float)
@Field(() => SafeIntResolver)
size!: number;
}

View File

@@ -23,13 +23,18 @@ type UserQuotaHumanReadable {
type UserQuota {
name: String!
blobLimit: Float!
storageQuota: Float!
historyPeriod: Float!
blobLimit: SafeInt!
storageQuota: SafeInt!
historyPeriod: SafeInt!
memberLimit: Int!
humanReadable: UserQuotaHumanReadable!
}
"""
The `SafeInt` scalar type represents non-fractional signed whole numeric values that are considered safe as defined by the ECMAScript specification.
"""
scalar SafeInt @specifiedBy(url: "https://www.ecma-international.org/ecma-262/#sec-number.issafeinteger")
type UserType {
id: ID!
@@ -172,7 +177,7 @@ type InvitationWorkspaceType {
}
type WorkspaceBlobSizes {
size: Float!
size: SafeInt!
}
type InvitationType {
@@ -309,7 +314,7 @@ type Query {
"""List blobs of workspace"""
listBlobs(workspaceId: String!): [String!]! @deprecated(reason: "use `workspace.blobs` instead")
collectAllBlobSizes: WorkspaceBlobSizes! @deprecated(reason: "use `user.storageUsage` instead")
checkBlobSize(workspaceId: String!, size: Float!): WorkspaceBlobSizes! @deprecated(reason: "no more needed")
checkBlobSize(workspaceId: String!, size: SafeInt!): WorkspaceBlobSizes! @deprecated(reason: "no more needed")
"""Get current user"""
currentUser: UserType

View File

@@ -74,7 +74,7 @@ export async function checkBlobSize(
.post(gql)
.auth(token, { type: 'bearer' })
.send({
query: `query checkBlobSize($workspaceId: String!, $size: Float!) {
query: `query checkBlobSize($workspaceId: String!, $size: SafeInt!) {
checkBlobSize(workspaceId: $workspaceId, size: $size) {
size
}