Skip to content

Commit

Permalink
Fix being able to have null language
Browse files Browse the repository at this point in the history
  • Loading branch information
jake-walker committed Feb 3, 2024
1 parent 60a8cb3 commit ceda350
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 16 deletions.
13 changes: 13 additions & 0 deletions app/cypress/e2e/basic.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ describe('Home Page', () => {
});
});

it('pastes without language set', () => {
cy.visit('/');
cy.get('[id$=-tab-paste]').click();

// fill in the form
cy.get("#paste-code").type("Hello World!").should("have.value", "Hello World!");
// submit the form
cy.get("#paste-submit").click();

// check the success alert is shown
cy.get("#success-alert").should("be.visible");
});

it('uploads', () => {
cy.visit('/');
cy.get('[id$=-tab-upload]').click();
Expand Down
2 changes: 0 additions & 2 deletions app/src/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ export function shortUrl(u) {

function parseExpiry(expiryDays) {
let expiryDate = null;
console.log("days", expiryDays);
expiryDays = parseInt(expiryDays);
console.log("days", expiryDays);
if (expiryDays > 0) {
expiryDate = new Date();
expiryDate.setDate(expiryDate.getDate() + expiryDays);
Expand Down
4 changes: 2 additions & 2 deletions worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
},
"scripts": {
"lint": "eslint ./src",
"dev": "wranger dev",
"dev": "wrangler dev",
"build": "webpack",
"publish": "wranger publish",
"publish": "wrangler publish",
"test": "vitest --run",
"migrate:generate": "drizzle-kit generate:sqlite --schema ./src/models.ts --out=./migrations",
"migrate:up": "drizzle-kit up:sqlite"
Expand Down
9 changes: 7 additions & 2 deletions worker/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@ export const ShortLinkArgs = BaseShortLinkArgs.and(BaseArgs);

const BasePasteArgs = z.object({
code: z.string(),
language: z.string().nullable().default(null).refine((val) => {
language: z.preprocess((val) => {
if (val === 'null') {
return null;
}
return val;
}, z.string().nullable().default(null).refine((val) => {
if (val === null) return true;
return languages.map((lang) => lang.id).includes(val);
}, { message: 'Language ID not supported' }),
}, { message: 'Language ID not supported' })),
});

export const PasteArgs = BasePasteArgs.and(BaseArgs);
Expand Down
29 changes: 19 additions & 10 deletions worker/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ compatibility_date = "2021-12-06"
workers_dev = true
main = "src/index.ts"

# [secrets]
# S3_ACCESS_KEY_ID
# S3_SECRET_ACCESS_KEY

[vars]
S3_ACCESS_KEY_ID = "minioadmin"
S3_SECRET_ACCESS_KEY = "minioadmin"
Expand All @@ -17,14 +13,27 @@ VH7_ENV = "development"
VH7_ADMIN_TOKEN = "keyboardcat"

[[d1_databases]]
binding = "DB" # i.e. available in your Worker on env.DB
database_name = "vh7"
database_id = "8248b645-7133-4795-a343-e9273706f77c"
preview_database_id = "c7e738c7-0b24-4c49-a3db-695e8658c01c"
binding = "DB"
database_name = "vh7-development"
database_id = "87904197-0107-411a-a030-be6ed70f8ff7"
migrations_dir = "migrations"

[env.production.vars]
S3_REGION = "eu-west-1"
S3_ENDPOINT_URL = "https://gateway.eu1.storjshare.io"
S3_BUCKET = "vh7-uploads"
S3_ENDPOINT_URL = "https://gateway.storjshare.io"
S3_BUCKET = "uploads"
VH7_ENV = "production"

[[env.production.d1_databases]]
binding = "DB"
database_name = "vh7"
database_id = "8248b645-7133-4795-a343-e9273706f77c"
migrations_dir = "migrations"

[[env.production.routes]]
pattern = "vh7.uk/*"
zone_name = "vh7.uk"

[[env.production.routes]]
pattern = "www.vh7.uk/*"
zone_name = "vh7.uk"

0 comments on commit ceda350

Please sign in to comment.