File size: 5,317 Bytes
8059bf0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<template>
  <Teleport to="body">
    <Transition name="sora-modal">
      <div v-if="visible && generation" class="sora-download-overlay" @click.self="emit('close')">
        <div class="sora-download-backdrop" />
        <div class="sora-download-modal" @click.stop>
          <div class="sora-download-modal-icon">📥</div>
          <h3 class="sora-download-modal-title">{{ t('sora.downloadTitle') }}</h3>
          <p class="sora-download-modal-desc">{{ t('sora.downloadExpirationWarning') }}</p>

          <!-- 倒计时 -->
          <div v-if="remainingText" class="sora-download-countdown">
            <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
              <path stroke-linecap="round" stroke-linejoin="round" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" />
            </svg>
            <span :class="{ expired: isExpired }">
              {{ isExpired ? t('sora.upstreamExpired') : t('sora.upstreamCountdown', { time: remainingText }) }}
            </span>
          </div>

          <div class="sora-download-modal-actions">
            <a
              v-if="generation.media_url"
              :href="generation.media_url"
              target="_blank"
              download
              class="sora-download-btn primary"
            >
              {{ t('sora.downloadNow') }}
            </a>
            <button class="sora-download-btn ghost" @click="emit('close')">
              {{ t('sora.closePreview') }}
            </button>
          </div>
        </div>
      </div>
    </Transition>
  </Teleport>
</template>

<script setup lang="ts">
import { ref, computed, watch, onUnmounted } from 'vue'
import { useI18n } from 'vue-i18n'
import type { SoraGeneration } from '@/api/sora'

const EXPIRATION_MINUTES = 15

const props = defineProps<{
  visible: boolean
  generation: SoraGeneration | null
}>()

const emit = defineEmits<{ close: [] }>()
const { t } = useI18n()

const now = ref(Date.now())
let timer: ReturnType<typeof setInterval> | null = null

const expiresAt = computed(() => {
  if (!props.generation?.completed_at) return null
  return new Date(props.generation.completed_at).getTime() + EXPIRATION_MINUTES * 60 * 1000
})

const isExpired = computed(() => {
  if (!expiresAt.value) return false
  return now.value >= expiresAt.value
})

const remainingText = computed(() => {
  if (!expiresAt.value) return ''
  const diff = expiresAt.value - now.value
  if (diff <= 0) return ''
  const minutes = Math.floor(diff / 60000)
  const seconds = Math.floor((diff % 60000) / 1000)
  return `${minutes}:${String(seconds).padStart(2, '0')}`
})

watch(
  () => props.visible,
  (v) => {
    if (v) {
      now.value = Date.now()
      timer = setInterval(() => { now.value = Date.now() }, 1000)
    } else if (timer) {
      clearInterval(timer)
      timer = null
    }
  },
  { immediate: true }
)

onUnmounted(() => {
  if (timer) clearInterval(timer)
})
</script>

<style scoped>
.sora-download-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sora-download-backdrop {
  position: absolute;
  inset: 0;
  background: var(--sora-modal-backdrop, rgba(0, 0, 0, 0.4));
  backdrop-filter: blur(4px);
}

.sora-download-modal {
  position: relative;
  z-index: 10;
  background: var(--sora-bg-secondary, #FFF);
  border: 1px solid var(--sora-border-color, #E5E7EB);
  border-radius: 20px;
  padding: 32px;
  max-width: 420px;
  width: 90%;
  text-align: center;
  animation: sora-modal-in 0.3s ease;
}

@keyframes sora-modal-in {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.sora-download-modal-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.sora-download-modal-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--sora-text-primary, #111827);
  margin-bottom: 8px;
}

.sora-download-modal-desc {
  font-size: 14px;
  color: var(--sora-text-secondary, #6B7280);
  margin-bottom: 20px;
  line-height: 1.6;
}

.sora-download-countdown {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 14px;
  color: var(--sora-text-secondary, #6B7280);
  margin-bottom: 24px;
}

.sora-download-countdown svg {
  color: var(--sora-text-tertiary, #9CA3AF);
}

.sora-download-countdown .expired {
  color: #EF4444;
}

.sora-download-modal-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.sora-download-btn {
  padding: 10px 24px;
  border-radius: 9999px;
  font-size: 14px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: all 150ms ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.sora-download-btn.primary {
  background: var(--sora-accent-gradient);
  color: white;
}

.sora-download-btn.primary:hover {
  box-shadow: var(--sora-shadow-glow);
}

.sora-download-btn.ghost {
  background: var(--sora-bg-tertiary, #F3F4F6);
  color: var(--sora-text-secondary, #6B7280);
}

.sora-download-btn.ghost:hover {
  background: var(--sora-bg-hover, #E5E7EB);
  color: var(--sora-text-primary, #111827);
}

/* 过渡 */
.sora-modal-enter-active,
.sora-modal-leave-active {
  transition: opacity 0.2s ease;
}
.sora-modal-enter-from,
.sora-modal-leave-to {
  opacity: 0;
}
</style>