File size: 3,313 Bytes
7ac86fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<script lang="ts">
  import { setApiKey } from '$lib/stores/story';

  export let onApiKeySet: ((apiKey: string) => void) | undefined = undefined;

  let inputKey = '';
  let isSet = false;

  function handleSubmit(event: Event) {
    event.preventDefault();

    if (inputKey.trim()) {
      setApiKey(inputKey.trim());
      isSet = true;
      onApiKeySet?.(inputKey.trim());
    }
  }

  function handleReset() {
    inputKey = '';
    isSet = false;
    setApiKey('');
  }
</script>

<div class="api-key-input">
  {#if !isSet}
    <div class="input-container">
      <h2>Enter OpenAI API Key</h2>
      <p class="description">
        Your API key is used to generate the story and videos with GPT-4 and Sora.
        It's stored only in your browser and never sent to our servers.
      </p>

      <form on:submit={handleSubmit}>
        <input
          type="password"
          bind:value={inputKey}
          placeholder="sk-..."
          class="api-key-field"
          required
        />
        <button type="submit" class="submit-button">
          Start Adventure
        </button>
      </form>

      <p class="info">
        Don't have an API key? Get one at <a href="https://platform.openai.com/api-keys" target="_blank" rel="noopener">OpenAI Platform</a>
      </p>
    </div>
  {:else}
    <div class="key-set">
      <p>✓ API Key Set</p>
      <button on:click={handleReset} class="reset-button">
        Change Key
      </button>
    </div>
  {/if}
</div>

<style>
  .api-key-input {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    min-height: 300px;
  }

  .input-container {
    max-width: 500px;
    width: 100%;
    text-align: center;
  }

  h2 {
    margin: 0 0 0.5rem 0;
    color: #1a1a1a;
    font-size: 1.75rem;
  }

  .description {
    color: #666;
    margin: 0 0 2rem 0;
    line-height: 1.5;
    font-size: 0.95rem;
  }

  form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }

  .api-key-field {
    padding: 0.75rem 1rem;
    font-size: 1rem;
    border: 2px solid #ddd;
    border-radius: 0.5rem;
    font-family: 'Monaco', 'Consolas', monospace;
  }

  .api-key-field:focus {
    outline: none;
    border-color: #007bff;
  }

  .submit-button {
    padding: 1rem 2rem;
    font-size: 1.1rem;
    font-weight: 600;
    background: #007bff;
    color: white;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: background 0.2s;
  }

  .submit-button:hover {
    background: #0056b3;
  }

  .info {
    margin-top: 1.5rem;
    font-size: 0.85rem;
    color: #666;
  }

  .info a {
    color: #007bff;
    text-decoration: none;
  }

  .info a:hover {
    text-decoration: underline;
  }

  .key-set {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.5rem;
    background: #d4edda;
    border: 1px solid #c3e6cb;
    border-radius: 0.5rem;
    color: #155724;
  }

  .key-set p {
    margin: 0;
    font-weight: 600;
  }

  .reset-button {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    background: white;
    color: #155724;
    border: 1px solid #c3e6cb;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: background 0.2s;
  }

  .reset-button:hover {
    background: #f1f1f1;
  }
</style>