File size: 1,823 Bytes
d6596e1
f237798
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import type { ProofInput, ProofValidation } from '../_types.js';

const WEB_HOSTS = ['vercel.app', 'onrender.com', 'netlify.app'];
const NOTEBOOK_HOSTS = ['colab.research.google.com', 'kaggle.com'];
const DESIGN_HOSTS = ['behance.net', 'dribbble.com', 'adobe.com'];

function hasKnownHost(url: string, hosts: string[]): boolean {
  try {
    const host = new URL(url).hostname.toLowerCase();
    return hosts.some((candidate) => host.endsWith(candidate));
  } catch {
    return false;
  }
}

export function validateProof(input: ProofInput): ProofValidation {
  const provided: string[] = [];
  const missing: string[] = [];

  if (input.liveDemoUrl) {
    provided.push('liveDemoUrl');
  }
  if (input.notebookUrl) {
    provided.push('notebookUrl');
  }
  if (input.portfolioUrl) {
    provided.push('portfolioUrl');
  }

  if (input.projectType === 'design') {
    const ok = !!input.portfolioUrl && hasKnownHost(input.portfolioUrl, DESIGN_HOSTS);
    if (!ok) {
      missing.push('Valid design portfolio URL (Behance/Dribbble)');
    }
    return {
      passed: ok,
      requiredProof: 'Design portfolio link',
      providedProof: provided,
      missing,
    };
  }

  if (input.projectType === 'web') {
    const ok = !!input.liveDemoUrl && hasKnownHost(input.liveDemoUrl, WEB_HOSTS);
    if (!ok) {
      missing.push('Valid web deployment URL (Vercel/Render/Netlify)');
    }

    return {
      passed: ok,
      requiredProof: 'Web deployment link',
      providedProof: provided,
      missing,
    };
  }

  const notebookOk = !!input.notebookUrl && hasKnownHost(input.notebookUrl, NOTEBOOK_HOSTS);
  if (!notebookOk) {
    missing.push('Valid Colab/Kaggle demo link');
  }

  return {
    passed: notebookOk,
    requiredProof: 'Notebook/demo proof link',
    providedProof: provided,
    missing,
  };
}